﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices;//互动服务
using IWshRuntimeLibrary;
using System.Threading;//线程序的命名空间
using System.Data.SqlClient;
using Excel = Microsoft.Office.Interop.Excel;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.Xml;
using System.Data;
using System.Data.OleDb;
using Outlook = Microsoft.Office.Interop.Outlook;

//using System.Configuration;
//using System.Web;
//using System.Web.Security;
//using System.Web.UI;
//using System.Web.UI.WebControls;
//using System.Web.UI.WebControls.WebParts;
//using System.Web.UI.HtmlControls;



namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        #region 变量声明区
        string _PWD = "";
        private System.Threading.Thread thdAddFile; //创建一个线程
        private string fn = "";
        FileStream FormerOpen;//实例化FileStream类
        FileStream ToFileOpen;//实例化FileStream类
        //public string str = "";//该变量保存INI文件所在的具体物理位置
        public string strOne = "";
        private string dir = "";
        private string dir_pick = "";
        private string dir_bak = "";
        int _SEC = 5000;
        int RE_BUG = 0;//记录BUG数
        SqlConnection conn, con, sqlcon;
        Form3 frm3;
        Frm_Ci frmci;
        Frm_Confirm frmconfirm;
        string[] R = new string[100];
        int i = 0;
        string _Version = "";
        XmlDocument doc = new XmlDocument();
        StringBuilder sb = new StringBuilder();
        public ArrayList Listtree = new ArrayList();
        string dt, nd, cm_check, client_l, client_d, unit, person1;
        List<Shortcut> P_Shortcut = new List<Shortcut>();
        List<Button> P_Button = new List<Button>();
        int shortcutseq = Convert.ToInt32(DateTime.Now.ToString("MMddHHmmss"));
        string checktype = "";
        string cimulu = "";
        Boolean flag=false;
        #endregion

        #region Form1构造函数

        public Form1()
        {
            InitializeComponent();
            //str = Application.StartupPath + "\\ConnectString.ini";						//INI文件的物理地址
            //strOne = System.IO.Path.GetFileNameWithoutExtension(str); 				//获取INI文件的文件名
            //if (System.IO.File.Exists(str)) 											//判断是否存在该INI文件
            //{
            //comboBox6.Text = ContentReader(strOne, "Data Source", "");				//读取INI文件中服务器节点的内容
            //textBox2.Text = ContentReader(strOne, "Data Source1", "");				//读取INI文件中数据库节点的内容
            //textBox3.Text = ContentReader(strOne, "Data Source2", "");			    //读取INI文件中用户节点的内容
            //textBox7.Text = ContentReader(strOne, "CMIP", "");          			//读取INI文件中密码节点的内容
            //dateTimePicker1.Text = ContentReader(strOne, "Start_Date", "");
            //comboBox8.Text = ContentReader(strOne, "person1", "");
            //comboBox5.Text = ContentReader(strOne, "group", "");
            //comboBox9.Text = ContentReader(strOne, "person2", "");
            //comboBox4.Text = ContentReader(strOne, "bug_Status", "");
            //comboBox7.Text = ContentReader(strOne, "bug_Type", "");
            //textBox6.Text = ContentReader(strOne, "directory_File", "");
            //textBox11.Text = ContentReader(strOne, "directory_File1", "");
            //textBox12.Text = ContentReader(strOne, "directory_File2", "");
            //textBox13.Text = ContentReader(strOne, "directory_File3", "");
            //textBox14.Text = ContentReader(strOne, "directory_File4", "");
            //textBox15.Text = ContentReader(strOne, "directory_File5", "");
            //textBox16.Text = ContentReader(strOne, "directory_File6", "");
            //textBox17.Text = ContentReader(strOne, "directory_File7", "");
            //textBox18.Text = ContentReader(strOne, "directory_File8", "");
            //textBox19.Text = ContentReader(strOne, "directory_File9", "");
            //textBox20.Text = ContentReader(strOne, "directory_File10", "");
            //textBox21.Text = ContentReader(strOne, "directory_File11", "");
            //textBox22.Text = ContentReader(strOne, "directory_File12", "");
            //textBox23.Text = ContentReader(strOne, "Driver", "");
            //textBox24.Text = ContentReader(strOne, "directory_File14", "");
            //textBox25.Text = ContentReader(strOne, "directory_File15", "");
            //toolStripTextBox1.Text = ContentReader(strOne, "DatebaseServer", "");
            //toolStripTextBox3.Text = ContentReader(strOne, "Pwd", "");
            //textBox30.Text = ContentReader(strOne, "ServerIP", "");
            //textBox31.Text = ContentReader(strOne, "ServerPort", "");
            //textBox32.Text = ContentReader(strOne, "CM_PWD", "");
            //textBox34.Text = ContentReader(strOne, "111_PWD", "");
            //textBox35.Text = ContentReader(strOne, "11_PWD", "");
            //textBox36.Text = ContentReader(strOne, "HJDZ_PWD", "");
            //textBox37.Text = ContentReader(strOne, "ALEX_PWD", "");
            //textBox33.Text = ContentReader(strOne, "SEC", "");
            //textBox38.Text = ContentReader(strOne, "Site", "");
            //textBox39.Text = ContentReader(strOne, "Programm", "");
            //textBox44.Text = ContentReader(strOne, "SPEC", "");
            //textBox45.Text = ContentReader(strOne, "SRC", "");
            //textBox46.Text = ContentReader(strOne, "BUG_TIME", "");
            //textBox47.Text = ContentReader(strOne, "SPEC_ADD", "");
            //}
            if (System.IO.File.Exists("DefaultData.xml"))
            {
                doc.Load("DefaultData.xml");
                XmlNode root = doc.SelectSingleNode("DataBase");
                XmlNodeList childlist = root.ChildNodes;
                comboBox6.Text = childlist[0].InnerText;
                textBox7.Text = childlist[1].InnerText;
                dateTimePicker1.Text = childlist[2].InnerText;
                comboBox8.Text = childlist[3].InnerText;
                comboBox9.Text = childlist[4].InnerText;
                unit = childlist[5].InnerText;
                textBox6.Text = childlist[6].InnerText;
                textBox19.Text = childlist[7].InnerText;
                textBox25.Text = childlist[8].InnerText;
                toolStripTextBox3.Text = childlist[9].InnerText;
                textBox30.Text = childlist[10].InnerText;
                textBox31.Text = childlist[11].InnerText;
                dt = childlist[12].InnerText;
                textBox38.Text = childlist[14].InnerText;
                textBox39.Text = childlist[15].InnerText;
                toolStripTextBox1.Text = childlist[16].InnerText;
                textBox46.Text = childlist[17].InnerText;
                textBox47.Text = childlist[18].InnerText;
                nd = childlist[19].InnerText;
                cm_check = childlist[20].InnerText;
                client_l = childlist[21].InnerText;
                client_d = childlist[22].InnerText;
                textBox23.Text = childlist[23].InnerText;
                //comboBox4.Text = childlist[24].InnerText;
                comboBox7.Text = childlist[25].InnerText;
                comboBox12.Text = childlist[26].InnerText;  //单据类型
                textBox4.Text = childlist[27].InnerText;    //CM数据库名称
                textBox33.Text = childlist[28].InnerText;    //3天结案率
                textBox48.Text = childlist[30].InnerText;    //默认IP
                textBox49.Text = childlist[31].InnerText;    //默认数据库
                textBox50.Text = childlist[32].InnerText;    //默认数据库密码
                textBox51.Text = childlist[33].InnerText;    //默认ITCODE
                textBox52.Text = childlist[34].InnerText;    //默认IT密码
                textBox53.Text = childlist[35].InnerText;    //默认报工路径
            }
            this.StartPosition = FormStartPosition.CenterScreen;
            Random r = new Random((int)DateTime.Now.Ticks);
            textBoxUserName.Text = Dns.GetHostName();
            listBoxOnline.HorizontalScrollbar = true;
        }

        #endregion



        //[DllImport("kernel32")]
        //private static extern int GetPrivateProfileString(
        //    string lpAppName,
        //    string lpKeyName,
        //    string lpDefault,
        //    StringBuilder lpReturnedString,
        //    int nSize,
        //    string lpFileName);

        //public string ContentReader(string area, string key, string def)
        //{
        //    StringBuilder stringBuilder = new StringBuilder(1024); 				//定义一个最大长度为1024的可变字符串
        //    GetPrivateProfileString(area, key, def, stringBuilder, 1024, str); 			//读取INI文件
        //    return stringBuilder.ToString();								//返回INI文件的内容
        //}

        //[DllImport("kernel32")]
        //private static extern long WritePrivateProfileString(
        //    string mpAppName,
        //    string mpKeyName,
        //    string mpDefault,
        //    string mpFileName);

        class HotKey
        {
            //以下方法用于注册热键 
            [DllImport("user32.dll", SetLastError = true)]
            public static extern bool RegisterHotKey(IntPtr hWnd, int Id, KeyModifiers fsModifiers, Keys vk);
            //以下方法用于注销热键 
            [DllImport("user32.dll", SetLastError = true)]
            public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
            public enum KeyModifiers
            {
                None = 0,
                Alt = 1,
                Ctrl = 2,
                Shift = 4,
                WindowKey = 8,
            }
        }

        #region 异步连接Server


        //是否正常退出
        private bool isExit = false;
        private TcpClient client;
        private BinaryReader br;
        private BinaryWriter bw;

        //BackgroundWorker connectWork = new BackgroundWorker();

        /// <summary>异步方式与服务器进行连接</summary>
        void ConnectToServer()
        {
            client = new TcpClient();
            //此处仅为方便本机调试，实际使用时要将Dns.GetHostName()改为服务器域名
            if (textBox30.Text == "")
            {
                textBox30.Text = "NJ-PUPEI-2";
            }
            if (textBox31.Text == "")
            {
                textBox31.Text = "9099";
            }
            try
            {
                IAsyncResult result = client.BeginConnect(textBox30.Text, Convert.ToInt32(textBox31.Text), null, null);//System.Net.Dns.GetHostEntry(textBox30.Text).AddressList[0].ToString()
                while (result.IsCompleted == false)
                {
                    Thread.Sleep(100);
                    AddStatus(".");
                }

                client.EndConnect(result);
                AddStatus("连接成功");
                toolStripStatusLabel1.Text = "成功连接服务器:" + textBox30.Text + " " + textBox31.Text;//System.Net.Dns.GetHostEntry(textBox30.Text).AddressList[0].ToString()
                //获取网络流
                NetworkStream networkStream = client.GetStream();
                //将网络流作为二进制读写对象
                br = new BinaryReader(networkStream);
                bw = new BinaryWriter(networkStream);
                AsyncSendMessage("Login," + Dns.GetHostName());
                Thread threadReceive = new Thread(new ThreadStart(ReceiveData));
                threadReceive.IsBackground = true;
                threadReceive.Start();
            }
            catch (Exception ex)
            {
                AddStatus("连接失败:" + ex.Message);
                buttonConnect.Enabled = true;
            }
        }

        /// <summary>
        /// 【连接服务器】按钮的Click事件
        /// </summary>
        private void buttonConnect_Click(object sender, EventArgs e)
        {
            buttonConnect.Enabled = false;
            AddStatus("开始连接.");
            ConnectToServer();
        }

        /// <summary>处理接收的服务器端数据</summary>
        private void ReceiveData()
        {
            //object sender=null; EventArgs e=null;
            string receiveString = null;
            while (isExit == false)
            {
                ReceiveMessageDelegate d = new ReceiveMessageDelegate(ReceiveMessage);
                IAsyncResult result = d.BeginInvoke(out receiveString, null, null);
                //使用轮询方式来判断异步操作是否完成
                while (result.IsCompleted == false)
                {
                    if (isExit)
                    {
                        break;
                    }
                    Thread.Sleep(250);
                }
                //获取Begin方法的返回值和所有输入/输出参数
                d.EndInvoke(out receiveString, result);
                if (receiveString == null)
                {
                    if (isExit == false)
                    {
                        MessageBox.Show("与服务器失去联系。");
                    }
                    break;
                }
                string[] splitString = receiveString.Split(',');
                string command = splitString[0].ToLower();
                switch (command)
                {
                    case "login":  //格式：login,用户名
                        AddOnline(splitString[1]);
                        break;
                    case "order":
                        break;
                    case "logout":  //格式：logout,用户名
                        RemoveUserName(splitString[1]);
                        break;
                    case "talk":  //格式：talk,用户名,对话信息
                        AddTalkMessage(splitString[1] + "：\r\n");
                        AddTalkMessage(receiveString.Substring(
                            splitString[0].Length + splitString[1].Length + 2));
                        break;
                    case "dinner":
                        frm3 = new Form3(this);
                        frm3.ShowDialog(this);
                        frm3.TopMost = true;
                        //this.TopMost = true;
                        //if (MessageBox.Show(this,"今天订饭吗？", "订饭", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        //{
                        //    button81_Click(sender, e);
                        //    this.TopMost = false;
                        //}
                        //else
                        //{
                        //    button82_Click(sender, e);
                        //    this.TopMost = false;
                        //}
                        break;
                }
            }
            //Application.Exit();
        }
        /// <summary>发送信息状态的数据结构</summary>
        private struct SendMessageStates
        {
            public SendMessageDelegate d;
            public IAsyncResult result;
        }

        /// <summary>异步向服务器端发送数据</summary>
        private void AsyncSendMessage(string message)
        {
            SendMessageDelegate d = new SendMessageDelegate(SendMessage);
            IAsyncResult result = d.BeginInvoke(message, null, null);
            while (result.IsCompleted == false)
            {
                if (isExit)
                {
                    return;
                }
                Thread.Sleep(50);
            }
            SendMessageStates states = new SendMessageStates();
            states.d = d;
            states.result = result;
            Thread t = new Thread(FinishAsyncSendMessage);
            t.IsBackground = true;
            t.Start(states);
        }
        /// <summary>处理接收的服务器端数据</summary>
        private void FinishAsyncSendMessage(object obj)
        {
            SendMessageStates states = (SendMessageStates)obj;
            states.d.EndInvoke(states.result);
        }
        delegate void SendMessageDelegate(string message);
        /// <summary>向服务器端发送数据</summary>
        private void SendMessage(string message)
        {
            try
            {
                bw.Write(message);
                bw.Flush();
            }
            catch
            {
                AddStatus("发送失败!");
            }
        }
        /// <summary>【发送】按钮的Click事件</summary>
        private void buttonSend_Click(object sender, EventArgs e)
        {
            if (listBoxOnline.SelectedIndex != -1)
            {
                AsyncSendMessage("Talk," + listBoxOnline.SelectedItem + "," + textBoxSend.Text + "\r\n");
                textBoxSend.Clear();
            }
            else
            {
                MessageBox.Show("请先在[当前在线]中选择一个对话者");
            }
        }

        delegate void ReceiveMessageDelegate(out string receiveMessage);
        /// <summary>读取服务器发过来的信息</summary>
        private void ReceiveMessage(out string receiveMessage)
        {
            receiveMessage = null;
            try
            {
                receiveMessage = br.ReadString();
            }
            catch (Exception ex)
            {
                AddStatus(ex.Message);
            }
        }
        private delegate void AddTalkMessageDelegate(string message);
        /// <summary>向richTextBoxTalkInfo中添加聊天记录</summary>
        private void AddTalkMessage(string message)
        {
            if (richTextBoxTalkInfo.InvokeRequired)
            {
                AddTalkMessageDelegate d = new AddTalkMessageDelegate(AddTalkMessage);
                richTextBoxTalkInfo.Invoke(d, new object[] { message });
            }
            else
            {
                richTextBoxTalkInfo.AppendText(message);
                richTextBoxTalkInfo.ScrollToCaret();
            }
        }
        private delegate void AddStatusDelegate(string message);
        /// <summary>向richTextBoxStatus中添加状态信息</summary>
        private void AddStatus(string message)
        {
            if (richTextBoxStatus.InvokeRequired)
            {
                AddStatusDelegate d = new AddStatusDelegate(AddStatus);
                richTextBoxStatus.Invoke(d, new object[] { message });
            }
            else
            {
                richTextBoxStatus.AppendText(message);
            }
        }
        private delegate void AddOnlineDelegate(string message);
        /// <summary>向listBoxOnline添加在线用户</summary>
        private void AddOnline(string message)
        {
            if (richTextBoxStatus.InvokeRequired)
            {
                AddOnlineDelegate d = new AddOnlineDelegate(AddOnline);
                richTextBoxStatus.Invoke(d, new object[] { message });
            }
            else
            {
                listBoxOnline.Items.Add(message);
                listBoxOnline.SelectedIndex = listBoxOnline.Items.Count - 1;
                listBoxOnline.ClearSelected();
            }
        }
        private delegate void RemoveUserNameDelegate(string userName);
        /// <summary>从listBoxOnline删除离线用户</summary>
        private void RemoveUserName(string userName)
        {
            if (richTextBoxStatus.InvokeRequired)
            {
                RemoveUserNameDelegate d = RemoveUserName;
                richTextBoxStatus.Invoke(d, userName);
            }
            else
            {
                listBoxOnline.Items.Remove(userName);
                listBoxOnline.SelectedIndex = listBoxOnline.Items.Count - 1;
                listBoxOnline.ClearSelected();
            }
        }
        /// <summary>关闭窗口时触发的事件</summary>
        //private void FormClient_FormClosing(object sender, FormClosingEventArgs e)
        //{
        //    if (client != null)
        //    {
        //        isExit = true;
        //        if (client.Client.Connected)
        //        {
        //            AsyncSendMessage("Logout," + Dns.GetHostName());
        //            br.Close();
        //            bw.Close();
        //        }
        //        client.Close();
        //    }
        //}


        #endregion

        #region 定义文件的复制的方法
        /// </summary>
        /// <param FormerFile="string">源文件路径</param>
        /// <param toFile="string">目的文件路径</param> 
        /// <param SectSize="int">传输大小</param> 
        /// <param progressBar="ProgressBar">ProgressBar控件</param> 
        public void CopyFile(string FormerFile, string toFile, int SectSize, ProgressBar progressBar1)
        {
            progressBar1.Value = 0;//设置进度栏的当前位置为0
            progressBar1.Minimum = 0;//设置进度栏的最小值为0
            FileStream fileToCreate = new FileStream(toFile, FileMode.Create);//创建目的文件，如果已存在将被覆盖
            fileToCreate.Close();//关闭所有资源
            fileToCreate.Dispose();//释放所有资源
            FormerOpen = new FileStream(FormerFile, FileMode.Open, FileAccess.Read);//以只读方式打开源文件
            ToFileOpen = new FileStream(toFile, FileMode.Append, FileAccess.Write);//以写方式打开目的文件
            int max = Convert.ToInt32(Math.Ceiling((double)FormerOpen.Length / (double)SectSize));//根据一次传输的大小，计算传输的个数
            progressBar1.Maximum = max;//设置进度栏的最大值
            int FileSize;//要拷贝的文件的大小
            if (SectSize < FormerOpen.Length)//如果分段拷贝，即每次拷贝内容小于文件总长度
            {
                byte[] buffer = new byte[SectSize];//根据传输的大小，定义一个字节数组
                int copied = 0;//记录传输的大小
                int tem_n = 1;//设置进度栏中进度块的增加个数
                while (copied <= ((int)FormerOpen.Length - SectSize))//拷贝主体部分
                {
                    FileSize = FormerOpen.Read(buffer, 0, SectSize);//从0开始读，每次最大读SectSize
                    FormerOpen.Flush();//清空缓存
                    ToFileOpen.Write(buffer, 0, SectSize);//向目的文件写入字节
                    ToFileOpen.Flush();//清空缓存
                    ToFileOpen.Position = FormerOpen.Position;//使源文件和目的文件流的位置相同
                    copied += FileSize;//记录已拷贝的大小
                    progressBar1.Value = progressBar1.Value + tem_n;//增加进度栏的进度块
                }
                int left = (int)FormerOpen.Length - copied;//获取剩余大小
                FileSize = FormerOpen.Read(buffer, 0, left);//读取剩余的字节
                FormerOpen.Flush();//清空缓存
                ToFileOpen.Write(buffer, 0, left);//写入剩余的部分
                ToFileOpen.Flush();//清空缓存
            }
            else//如果整体拷贝，即每次拷贝内容大于文件总长度
            {
                byte[] buffer = new byte[FormerOpen.Length];//获取文件的大小
                FormerOpen.Read(buffer, 0, (int)FormerOpen.Length);//读取源文件的字节
                FormerOpen.Flush();//清空缓存
                ToFileOpen.Write(buffer, 0, (int)FormerOpen.Length);//写放字节
                ToFileOpen.Flush();//清空缓存
            }
            FormerOpen.Close();//释放所有资源
            ToFileOpen.Close();//释放所有资源
            if (MessageBox.Show("复制完成") == DialogResult.OK)//显示"复制完成"提示对话框
            {
                progressBar1.Value = 0;//设置进度栏的当有位置为0

            }
        }

        #endregion

        #region Form1加载

        private void Form1_Load(object sender, EventArgs e)
        {
            frm3 = new Form3(this);
            frmci = new Frm_Ci(this);
            frmconfirm = new Frm_Confirm(this);
            HotKey.RegisterHotKey(Handle, 100, HotKey.KeyModifiers.Shift, Keys.F1); //注册Shift+F1  工具最小化
            HotKey.RegisterHotKey(Handle, 200, HotKey.KeyModifiers.Ctrl, Keys.F11); //注册Ctrl+F11  填密码
            HotKey.RegisterHotKey(Handle, 300, HotKey.KeyModifiers.Ctrl, Keys.F10); //注册Ctrl+F10  报工
            HotKey.RegisterHotKey(Handle, 400, HotKey.KeyModifiers.Ctrl, Keys.F9); //注册Ctrl+F9    停止报工
            HotKey.RegisterHotKey(Handle, 500, HotKey.KeyModifiers.Shift, Keys.F2); //注册Shift+F2  停止平台S+C
            buttonConnect_Click(sender, e);
            toolStripStatusLabel3.Text = "登录时间：" + DateTime.Now.ToString("yyyy/MM/dd/HH/mm/ss");
            this.notifyIcon1.Visible = true;
            listBoxOnline.Items.Add("全部");
            //radioButton13.Enabled = false;
            //radioButton14.Enabled = false;
            //radioButton15.Enabled = false;
            //radioButton16.Enabled = false;
            //radioButton14.Checked = false;
            _PWD = textBox34.Text;
            textBox4.Text = "CM";
            if (textBox46.Text != "")
            {
                timer1.Interval = (int)(Convert.ToDecimal(textBox46.Text) * 60 * 1000);
            }
            ReadProduct(comboBoxproduct);
            ReadProduct(comboBoxproduct1);
            ReadProduct(comboBoxproduct2);
            ReadProduct(comboBoxproduct12);
            ReadPerson(comboBox8);
            button46_Click(sender, e);
            //Dir1_Load(sender, e);
            Dir3_Load(sender, e);
            // Dir2_Load(sender, e); 
            this.tabControl1.TabPages.Remove(this.tabPage4);
            this.tabControl1.TabPages.Remove(this.tabPage8);
            this.tabControl1.TabPages.Remove(this.tabPage9);
            this.tabControl1.TabPages.Remove(this.tabPage10);
            //if (textBox33.Text != "")
            //{
            //    _SEC = Convert.ToInt32(textBox33.Text) * 1000;
            //}
            //ReadProduct(comboBoxproduct);
            //ReadProduct(comboBoxproduct1);
            //ReadProduct(comboBoxproduct2);
            //ReadProduct(comboBoxproduct3);
            //comboBoxproduct.Text = comboBoxproduct.Items[4].ToString();
            //comboBoxproduct1.Text = comboBoxproduct1.Items[4].ToString();
            //comboBoxproduct2.Text = comboBoxproduct2.Items[4].ToString();
            //comboBoxproduct12.Text = comboBoxproduct12.Items[4].ToString();
            ReadText("dir.txt");
            //button40_Click(sender, e);
            //button46_Click(sender, e);
            //comboBox1.Text = "Designer Project";
            Version();
            //ReadConfig();
            chkSpec_CheckedChanged(sender, e);
            //this.AcceptButton = btniQueryStart;
            ReadProduct(comboBoxproduct3);
            comboBoxproduct3.Text = comboBoxproduct3.Items[5].ToString();
            //if (!System.IO.Directory.Exists(comboBox6.Text + "\\Server\\"))
            //{
            //    button3.Enabled = false;
            //    button5.Enabled = false;
            //}
            //else
            //{
            //    button3.Enabled = true;
            //    button5.Enabled = true;
            //}
            if (cm_check == "true")
            {
                checkBox7.Checked = true;
            }
            else
            {
                checkBox7.Checked = false;
            }
            if (client_l == "true")
            {
                checkBox8.Checked = true;
            }
            else
            {
                checkBox8.Checked = false;
            }
            if (client_d == "true")
            {
                //if (!System.IO.Directory.Exists(comboBox6.Text + "\\Server\\"))
                //{
                //    checkBox10.Checked = false;
                //}
                //else
                //{
                checkBox10.Checked = true;
                //}

            }
            else
            {
                checkBox10.Checked = false;
            }
            doc.Load("TreeXml.xml"); //我是把xml放到debug里面了.你的路径就随便啦.不过这样方便一些.
            RecursionTreeControl(doc.DocumentElement, Trv_Config.Nodes, nd);//将加载完成的XML文件显示在TreeView控件中
            //Trv_Config.CollapseAll();//折叠TreeView控件中的所有项
            //if (Trv_Config.Nodes.Count > 0)
            //{
            //TreeNode tn =SearchNode(Trv_Config.Nodes,ContentReader(strOne, "Node", ""));

            //XmlNode xd = doc.SelectSingleNode("/[@Name='" + ContentReader(strOne, "Node", "") + "']");

            //    Trv_Config.SelectedNode = CurrentNode.Nodes[name]xd;
            //    Trv_Config.SelectedNode = Trv_Config.Nodes[0];
            //    Trv_Config.SelectedNode.Expand();
            //}
            comboBox5.Text = unit;
            //DataGridViewCheckBoxColumn dgvc = new DataGridViewCheckBoxColumn();//创建列对象
            //dgvc.HeaderText = "选择";//设置列标题文本
            //ShortcutGrid.Columns.Insert(0, dgvc);//添加列
            //ShortcutGrid.Columns[0].Width = 50;
            this.MainBindingSource.DataSource = P_Shortcut;
            //this.MainBindingSource.ListChanged += MainBindingSource_ListChanged;
            //ShortcutGrid.DataSource = P_Shortcut;
            LoadShortcut();
            doc.Load("DataServer.xml");
            XmlNodeList nl_server = doc.SelectNodes("/DataServer/Server");
            foreach (XmlNode nd_server in nl_server)
            {
                toolStripTextBox1.Items.Add(nd_server.Attributes[0].Value);
                comboBox15.Items.Add(nd_server.Attributes[0].Value);
            }
        }

        //private void MainBindingSource_ListChanged(object sender, ListChangedEventArgs e)
        //{
        //    if (e.ListChangedType == ListChangedType.ItemAdded)
        //    {
        //        //增加Button
        //        Button bt = new Button();
        //        bt.Name = shortcutseq.ToString();
        //        bt.Text = shortcutseq.ToString();
        //        P_Button.Add(bt);
        //        flowLayoutPanel4.Controls.Add(bt);
        //        bt.Click += bt_Click;
        //    }
        //    throw new NotImplementedException();
        //}

        #endregion

        #region 本地平台区
        private void Dir3_Load(object sender, EventArgs e)
        {
            comboBoxConfig.Items.Clear();
            DirectoryInfo dinfo = null;
            dinfo = new DirectoryInfo(System.Environment.CurrentDirectory + "\\Config File");
            //获取指定目录下的所有子目录及文件类型
            FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
            foreach (FileSystemInfo fsinfo in fsinfos)
            {
                comboBoxConfig.Items.Add(fsinfo.Name);
            }
        }

        private void ReadConfig()
        {
            XmlNode xmlnode;
            XmlNodeList nodeList;
            XmlElement xmlelem;
            XmlDocument xmlDoc = new XmlDocument();
            dataGridView3.Rows.Clear();
            dataGridView3.Rows.Add(3);
            if (System.IO.File.Exists(comboBox6.Text + "//Server//AccountSetsConfiguration.xml"))
            {
                xmlDoc.Load(comboBox6.Text + "//Server//AccountSetsConfiguration.xml");
            }
            else if (System.IO.File.Exists(comboBox6.Text + "//Server//control//AccountSetsConfiguration.xml"))
            {
                xmlDoc.Load(comboBox6.Text + "//Server//control//AccountSetsConfiguration.xml");
            }
            else
            {
                return;
            }

            nodeList = xmlDoc.SelectSingleNode("//AccountSets").ChildNodes;

            int j = 0;
            foreach (XmlNode xn in nodeList)
            {
                if (xn.Name == "#comment")
                {
                    continue;
                }
                XmlElement xe = (XmlElement)xn;
                XmlNodeList nls = xe.ChildNodes;
                foreach (XmlNode xn1 in nls)
                {
                    if (xn1.Name == "#comment")
                    {
                        continue;
                    }
                    XmlElement xe1 = (XmlElement)xn1;
                    // if ((xe1.Name == "BootType") && (xe1.InnerText == "0" || xe1.InnerText == "Auto"))//如果找到 
                    if (xe1.Name == "BootType")//如果找到 
                    {
                        foreach (XmlNode xn2 in nls)
                        {
                            if (xn2.Name == "#comment")
                            {
                                continue;
                            }
                            XmlElement xe2 = (XmlElement)xn2;
                            if (xe2.Name == "DBSetting")
                            {
                                XmlNodeList nlss = xe2.ChildNodes;
                                foreach (XmlNode xn3 in nlss)
                                {
                                    if (xn3.Name == "#comment")
                                    {
                                        continue;
                                    }
                                    XmlElement xe3 = (XmlElement)xn3;
                                    XmlNodeList nlsss = xe3.ChildNodes;
                                    foreach (XmlNode xn4 in nlsss)
                                    {
                                        if (xn4.Name == "#comment")
                                        {
                                            continue;
                                        }
                                        XmlElement xe4 = (XmlElement)xn4;
                                        if (xe4.Name == ("ConnectionString"))
                                        {
                                            // xe4.InnerText = "Data Source=" + textBox40.Text + ";Initial Catalog=" + textBox41.Text + ";User ID=" + textBox42.Text + ";Password=" + textBox43.Text + ";Pooling=true;Max Pool Size=4000";
                                            Array sp = xe4.InnerText.Split(';');
                                            if (sp.Length < 2)
                                            {
                                                MessageBox.Show("请先解密配置文件");
                                                return;
                                            }
                                            dataGridView3.Rows[0 + j].Cells[0].Value = xe4.InnerText.Split(';')[0].Substring(12);
                                            dataGridView3.Rows[0 + j].Cells[1].Value = xe4.InnerText.Split(';')[1].Substring(16);
                                            dataGridView3.Rows[0 + j].Cells[2].Value = xe4.InnerText.Split(';')[2].Substring(8);
                                            if (xe4.InnerText.Split(';')[3].Substring(0, 8) == "Password")
                                            {
                                                dataGridView3.Rows[0 + j].Cells[3].Value = xe4.InnerText.Split(';')[3].Substring(9);
                                            }
                                            else
                                            {
                                                dataGridView3.Rows[0 + j].Cells[3].Value = xe4.InnerText.Split(';')[3].Substring(4);
                                            }
                                            dataGridView3.Rows[0 + j].Cells[4].Value = xe1.InnerText;
                                            j++;
                                        }

                                    }
                                }
                            }

                        }
                    }
                }
            }

        }

        private void SaveConfig()
        {
            XmlNode xmlnode;
            XmlNodeList nodeList;
            XmlElement xmlelem;
            XmlDocument xmlDoc = new XmlDocument();

            if (System.IO.File.Exists(comboBox6.Text + "//Server//AccountSetsConfiguration.xml"))
            {
                xmlDoc.Load(comboBox6.Text + "//Server//AccountSetsConfiguration.xml");
            }
            else if (System.IO.File.Exists(comboBox6.Text + "//Server//control//AccountSetsConfiguration.xml"))
            {
                xmlDoc.Load(comboBox6.Text + "//Server//control//AccountSetsConfiguration.xml");
            }
            else
            {
                return;
            }

            nodeList = xmlDoc.SelectSingleNode("/AccountSetsConfiguration/AccountSets").ChildNodes;
            //if (_Version == "2.0")
            //{
            //    nodeList = xmlDoc.SelectSingleNode("/AccountSetsConfiguration/AccountSets").ChildNodes;
            //}
            //else
            //{
            //    nodeList = xmlDoc.SelectSingleNode("/AccountSetsConfigurationElement/AccountSets").ChildNodes;
            //}
            int j = 0;
            foreach (XmlNode xn in nodeList)
            {
                if (xn.Name == "#comment")
                {
                    continue;
                }
                XmlElement xe = (XmlElement)xn;
                XmlNodeList nls = xe.ChildNodes;
                foreach (XmlNode xn1 in nls)
                {
                    if (xn1.Name == "#comment")
                    {
                        continue;
                    }
                    XmlElement xe1 = (XmlElement)xn1;
                    // if ((xe1.Name == "BootType") && (xe1.InnerText == "0" || xe1.InnerText == "Auto"))//如果找到 

                    if (xe1.Name == "BootType")//如果找到 
                    {
                        xe1.InnerText = dataGridView3.Rows[0 + j].Cells[4].Value.ToString();
                        foreach (XmlNode xn2 in nls)
                        {
                            if (xn2.Name == "#comment")
                            {
                                continue;
                            }
                            XmlElement xe2 = (XmlElement)xn2;
                            if (xe2.Name == "DBSetting")
                            {
                                XmlNodeList nlss = xe2.ChildNodes;
                                foreach (XmlNode xn3 in nlss)
                                {
                                    if (xn3.Name == "#comment")
                                    {
                                        continue;
                                    }
                                    XmlElement xe3 = (XmlElement)xn3;
                                    XmlNodeList nlsss = xe3.ChildNodes;
                                    foreach (XmlNode xn4 in nlsss)
                                    {
                                        if (xn4.Name == "#comment")
                                        {
                                            continue;
                                        }
                                        XmlElement xe4 = (XmlElement)xn4;
                                        if (xe4.Name == ("ConnectionString"))
                                        {
                                            xe4.InnerText = "Data Source=" + dataGridView3.Rows[0 + j].Cells[0].Value + ";Initial Catalog=" + dataGridView3.Rows[0 + j].Cells[1].Value + ";User ID=" + dataGridView3.Rows[0 + j].Cells[2].Value + ";Password=" + dataGridView3.Rows[0 + j].Cells[3].Value + ";Pooling=true;Max Pool Size=4000";
                                            j++;
                                        }

                                    }
                                }
                            }

                        }
                    }
                }
            }
            xmlnode = xmlDoc.SelectSingleNode("//AccountSetId");
            xmlnode.InnerText = dataGridView3.Rows[0].Cells[1].Value.ToString();
            xmlnode = xmlDoc.SelectSingleNode("//Caption");
            xmlnode.InnerText = dataGridView3.Rows[0].Cells[1].Value.ToString();
            xmlnode = xmlDoc.SelectSingleNode("//Description");
            xmlnode.InnerText = dataGridView3.Rows[0].Cells[1].Value.ToString();
            if (System.IO.File.Exists(comboBox6.Text + "//Server//AccountSetsConfiguration.xml"))
            {
                xmlDoc.Save(comboBox6.Text + "//Server//AccountSetsConfiguration.xml");
            }
            else
            {
                xmlDoc.Save(comboBox6.Text + "//Server//control//AccountSetsConfiguration.xml");
            }
        }

        private void button31_Click(object sender, EventArgs e)    //保存环境按钮
        {
            if (System.IO.Directory.Exists(comboBox6.Text + "\\Server\\"))
            {
                SaveConfig();
            }
            Save_Environment();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //copyDirectory(System.Environment.CurrentDirectory + "\\Config File\\" + comboBoxConfig.Text, comboBox6.Text);
            //MessageBox.Show("成功配置本地" + comboBox6.Text + "平台");

            XmlNode node;
            XmlElement xe;
            XmlNodeList nodes;
            //string ver;
            ////查出version
            //doc.Load(comboBox6.Text + "//Server//Application//Version.xml");
            //node = doc.SelectSingleNode("/VersionObject/Version");
            //ver=node.InnerText.Substring(0,5);
            //修改AccountSetsConfiguration.xml
            doc.Load(comboBox6.Text + "//Server//Control//AccountSetsConfiguration.xml");
            nodes = doc.SelectNodes("//NetSetting/BindToIP");

            foreach (XmlNode item in nodes)
            {
                item.InnerText = textBox48.Text;
            }
            if (localLC_chk.Checked)
            {
                node = doc.SelectSingleNode("//LicenseCenter/BindToIP");
                node.InnerText = textBox48.Text;
            }
            node = doc.SelectSingleNode("//AccountSetId");
            node.InnerText = textBox49.Text;
            node = doc.SelectSingleNode("//Caption");
            node.InnerText = textBox49.Text;
            node = doc.SelectSingleNode("//Description");
            node.InnerText = textBox49.Text;
            node = doc.SelectSingleNode("//ConnectionString");
            node.InnerText = "Data Source=" + textBox48.Text + ";Initial Catalog=" + textBox49.Text + ";User ID=sa;Password=" + textBox50.Text + ";Pooling=true;Max Pool Size=4000";
            node = doc.SelectSingleNode("//AccountSets");
            while (node.ChildNodes.Count > 1)
            {
                node.RemoveChild(doc.SelectSingleNode("//AccountSets/AccountSet[2]"));
            }
            doc.Save(comboBox6.Text + "//Server//Control//AccountSetsConfiguration.xml");
            //修改AutoRun.Client.dcxml
            doc.Load(comboBox6.Text + "//DeployServer//Shared//AutoRun.Client.dcxml");
            node = doc.SelectSingleNode("/AutoRun/TypeKeys/AutoRunItem[1]/ApplyTo");
            if (node != null)
            {
                node.ParentNode.RemoveChild(node);
            }

            node = doc.SelectSingleNode("//BaseItems/BaseFunctionPackage[PropertyName='ForAutoUpdateSetting']");
            if (node != null)
            {
                node.ParentNode.RemoveChild(node);
            }
            doc.Save(comboBox6.Text + "//DeployServer//Shared//AutoRun.Client.dcxml");
            //修改Digiwin.Mars.ClientStart.exe.config
            //if (ver == "1.0.0" || ver == "2.0.0" || ver == "2.0.1")
            //{
            doc.Load(comboBox6.Text + "//DeployServer//Shared//Digiwin.Mars.ClientStart.exe.config");
            node = doc.SelectSingleNode("//add[@key='PortalAddress']");
            if (node != null)
            {
                xe = (XmlElement)node;
                xe.SetAttribute("value", "http://" + textBox48.Text + "/" + textBox39.Text + "/WebMain.aspx");
            }
            doc.Save(comboBox6.Text + "//DeployServer//Shared///Digiwin.Mars.ClientStart.exe.config");
            //}
            //修改Default.dcc
            doc.Load(comboBox6.Text + "//DeployServer//Shared//Default.dcc");
            node = doc.SelectSingleNode("//ServerUrl");
            node.InnerText = "tcp://" + textBox48.Text + ":8043/ServiceProvider.rem";
            node = doc.SelectSingleNode("//WebServerUrl");
            if (node != null)
            {
                node.InnerText = "http://" + textBox48.Text + "/" + textBox39.Text + "/WebMain.aspx";
            }
            doc.Save(comboBox6.Text + "//DeployServer//Shared//Default.dcc");
            MessageBox.Show("成功配置本地" + comboBox6.Text + "平台");
            ReadConfig();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = comboBox6.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                comboBox6.Text = folderBrowserDialog1.SelectedPath;
                comboBox6_SelectedValueChanged(sender, e);
                string cmd = "c:\\windows\\system32\\inetsrv\\appcmd.exe set app /app.name: " + "\"" + textBox38.Text + "/" + textBox39.Text + "\"" + " /[path='/'].physicalpath:" + "\"" + comboBox6.Text + "\\WebServer" + "\"";
                //Process.Start(@"c:\windows\system32\inetsrv\appcmd.exe", "set app pupei/WebServer /[path='/'].physicalpath:" + "\"" + comboBox6.Text + "\\WebServer" + "\"");
                Execute(cmd, 0);
            }


            doc.Load("DefaultData.xml");
            XmlNode nd = doc.SelectSingleNode("//Data_Source");
            nd.InnerText = comboBox6.Text;
            doc.Save("DefaultData.xml");
            bool flag = false;
            foreach (object list in comboBox6.Items)
            {
                if (comboBox6.Text.ToString().Equals(list))
                {
                    flag = true;
                }
            }

            if (!flag)
            {
                comboBox6.Items.Add(comboBox6.Text);
                WriteTxt(comboBox6.Text, "dir.txt");
            }

        }

        private void button24_Click(object sender, EventArgs e)
        {
            if (comboBox6.Text == "")
            {
                Process.Start("D:\\");
            }
            else
            {
                Process.Start(comboBox6.Text);
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {

            string Arg = "";
            if (checkBox1.Checked)
            {
                Arg += "/p ";
            }
            if (checkBox2.Checked)
            {
                Arg += "/r ";
            }
            if (checkBox3.Checked)
            {
                Arg += "/l ";
            }
            if (checkBox4.Checked)
            {
                Arg += "/d";
            }
            if (chk_update_date.Checked)
            {
                Arg += "/u";
            }
            WshShell shell = new WshShell();
            //IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) +"\\" + "PuPei’s 平台S端.lnk");
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" + "\\" + comboBox6.Text.Substring(comboBox6.Text.LastIndexOf('\\')) + "---" + dataGridView3.Rows[0].Cells[1].Value + " 平台S端.lnk");
            shortcut.TargetPath = comboBox6.Text + "\\Server\\Digiwin.Mars.ServerStart.exe";
            shortcut.TargetPath = comboBox6.Text + "\\Server\\control\\Digiwin.Mars.ServerStart.exe";
            shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application S";
            shortcut.Arguments = Arg;
            //shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.IconLocation = System.Environment.CurrentDirectory + "\\server.ico, 0";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp" + "\\" + comboBox6.Text.Substring(comboBox6.Text.LastIndexOf('\\')) + "---" + dataGridView3.Rows[0].Cells[1].Value + " 平台S端.lnk");
            Record_MWH("1");
        }

        //private void button6_Click(object sender, EventArgs e)   //启动C端WEB
        //{
        //    if (_Version == "2.0")
        //    {
        //        Process.Start(@comboBox6.Text + "\\DeployServer\\Shared\\Digiwin.Mars.ClientStart.exe");
        //    }
        //    else if (System.IO.File.Exists(@comboBox6.Text + "\\Client\\Digiwin.Mars.ClientStart.exe"))
        //    {
        //        Process.Start(@comboBox6.Text + "\\Client\\Digiwin.Mars.ClientStart.exe");
        //    }
        //    else
        //    {
        //        Process.Start(@comboBox6.Text + "\\Digiwin.Mars.ClientStart.exe");
        //    }
        //    Thread.Sleep(_SEC);
        //    login("", _PWD);
        //    Record_MWH("1");
        //}

        private void button7_Click(object sender, EventArgs e)
        {
            string Arg = "";
            if (checkBox8.Checked)
            {
                Arg = "/L ";
            }
            if (checkBox10.Checked)
            {
                Arg = "d /L ";
            }

            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "PuPei’s 平台C端.lnk");
            if (System.IO.Directory.Exists(comboBox6.Text + "\\Server\\"))
            {
                shortcut.TargetPath = comboBox6.Text + "\\Client\\Digiwin.Mars.ClientStart.exe";
                shortcut.TargetPath = comboBox6.Text + "\\DeployServer\\Shared\\Digiwin.Mars.ClientStart.exe";
                shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
            }
            else
            {
                shortcut.TargetPath = comboBox6.Text + "\\Digiwin.Mars.Deployment.Client.exe";
                shortcut.WorkingDirectory = comboBox6.Text;
            }
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application C";
            shortcut.Arguments = Arg;
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp" + "\\" + "PuPei’s 平台C端.lnk");
            Thread.Sleep(_SEC);
            login("", _PWD);
            Record_MWH("1");
        }  
        
        
        //启动C端LIST

        //   private void button8_Click(object sender, EventArgs e) //调试C
        //   {
        //       WshShell shell = new WshShell();
        //       IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
        //"\\" + "PuPei’s 调试C端.lnk");
        //       shortcut.TargetPath = comboBox6.Text + "\\Client\\Digiwin.Mars.ClientStart.exe";
        //       shortcut.TargetPath = comboBox6.Text + "\\DeployServer\\Shared\\Digiwin.Mars.ClientStart.exe";
        //       shortcut.TargetPath = comboBox6.Text + "\\Digiwin.Mars.ClientStart.exe";
        //       shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
        //       shortcut.WindowStyle = 1;
        //       shortcut.Description = "Launch Patrick’s Application 调试C";
        //       shortcut.Arguments = "d /L";
        //       shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
        //       shortcut.Save();
        //       Process.Start("C:\\Windows\\Temp" +"\\" + "PuPei’s 调试C端.lnk");
        //       Thread.Sleep(_SEC);
        //       login("", _PWD);
        //       Record_MWH("1");
        //   }

        //关闭S和C
        public void button53_Click(object sender, EventArgs e)
        {
            Process[] ps = Process.GetProcesses();
            foreach (Process item in ps)
            {
                if (item.ProcessName == "Digiwin.Mars.ServerStart")
                {
                    item.Kill();
                }
                //if (item.ProcessName == "Digiwin.Mars.ClientStart")
                //{
                //    foreach (string s in R)
                //    {
                //        if (s == null)
                //        {
                //            break;
                //        }
                //        string[] sp = s.Split('.');
                //        if (sp[1] == "1" && sp[0].Equals(item.Id.ToString()))
                //        {
                //            item.Kill();
                //        }
                //    }
                //}
                if (item.ProcessName == "Digiwin.Mars.ClientStart")
                {
                    if (item.MainModule.FileName != textBox25.Text + "\\Digiwin.Mars.ClientStart.exe")
                    {
                        item.Kill();
                    }
                }

            }
        }

        //关闭C
        public void button55_Click(object sender, EventArgs e)
        {
            Process[] ps = Process.GetProcesses();
            foreach (Process item in ps)
            {
                if (item.ProcessName == "Digiwin.Mars.ClientStart")
                {
                    if (item.MainModule.FileName != textBox25.Text + "\\Digiwin.Mars.ClientStart.exe")
                    {
                        item.Kill();
                    }
                    //foreach (string s in R)
                    //{
                    //    if (s == null)
                    //    {
                    //        break;
                    //    }
                    //    string[] sp = s.Split('.');
                    //    if (sp[1] == "1" && sp[0].Equals(item.Id.ToString()))
                    //    {
                    //        item.Kill();
                    //    }
                    //}
                    //    MessageBox.Show("当前进程名:" + item.ProcessName.ToString()
                    //+ "\nPID:" + item.Id
                    //+ "\n进程路径:" + item.MainModule.FileName
                    //+ "\n线程数:" + item.Threads.Count
                    //+ "\n句柄数:" + item.HandleCount
                    //+ "\n内存使用:" + item.WorkingSet64.ToString()
                    //+ "\n虚拟内存:" + item.VirtualMemorySize64.ToString());
                }
            }
        }

        private void 清空_Click(object sender, EventArgs e)
        {
            comboBox6.Items.Clear();
            var Current = Directory.GetCurrentDirectory();//获取当前根目录
            System.IO.File.Delete(Current + "\\dir.txt");
            FileStream fs = System.IO.File.Create(Current + "\\dir.txt");
            fs.Close();
        }

        private void chk_update_date_CheckedChanged(object sender, EventArgs e)
        {
            if (chk_update_date.Checked)
            {
                checkBox1.Checked = false;
                checkBox2.Checked = false;
                checkBox3.Checked = false;
                checkBox4.Checked = false;
                checkBox1.Enabled = false;
                checkBox2.Enabled = false;
                checkBox3.Enabled = false;
                checkBox4.Enabled = false;
            }
            if (chk_update_date.Checked == false)
            {
                checkBox1.Checked = false;
                checkBox2.Checked = false;
                checkBox3.Checked = false;
                checkBox4.Checked = true;
                checkBox1.Enabled = true;
                checkBox2.Enabled = true;
                checkBox3.Enabled = true;
                checkBox4.Enabled = true;
            }
        }

        private void button15_Click(object sender, EventArgs e) //查看PROGRAMMINFO
        {
            if (!System.IO.Directory.Exists(comboBox6.Text + "\\Server\\"))
            {
                if (System.IO.Directory.Exists(@comboBox6.Text + "\\BusinessObjects\\ProgramInfoContainerElement\\"))
                {
                    Process.Start(@comboBox6.Text + "\\BusinessObjects\\ProgramInfoContainerElement\\ProgramInfoContainer.dcxml");
                }
                else
                {
                    MessageBox.Show("文件不存在！");
                }
            }
            else
            {
                if (_Version == "2.0")
                {
                    Process.Start(@comboBox6.Text + "\\DeployServer\\Shared\\BusinessObjects\\ProgramInfoContainerElement\\ProgramInfoContainer.dcxml");
                }
                else
                {
                    Process.Start(@comboBox6.Text + "\\Client\\BusinessObjects\\ProgramInfoContainerElement\\ProgramInfoContainer.dcxml");
                }
            }
        }

        private void button18_Click(object sender, EventArgs e)
        {
            XmlDocument xmlDoc;


            xmlDoc = new XmlDocument();
            //xmlDoc.Load(comboBox6.Text+"//Client//BusinessObjects//ProgramInfoContainerElement//ProgramInfoContainer.dcxml");
            if (_Version == "2.0")
            {
                xmlDoc.Load(comboBox6.Text + "//DeployServer//Shared//BusinessObjects//ProgramInfoContainerElement//ProgramInfoContainer.dcxml");
            }
            else
            {
                xmlDoc.Load(comboBox6.Text + "//Client//BusinessObjects//ProgramInfoContainerElement//ProgramInfoContainer.dcxml");
            }
            XmlNodeList nodeList = xmlDoc.SelectSingleNode("ProgramInfoContainer").ChildNodes;//获取ProgramInfoContainer节点的所有子节点 
            foreach (XmlNode xn in nodeList)//遍历所有子节点
            {
                if (xn.Name == "#comment")
                {
                    continue;
                }
                XmlElement xe = (XmlElement)xn;//将子节点类型转换为XmlElement类型 

                XmlNodeList nls = xe.ChildNodes;//继续获取xe子节点的所有子节点 
                foreach (XmlNode xn1 in nls)//遍历 
                {
                    if (xn1.Name == "#comment")
                    {
                        continue;
                    }
                    XmlElement xe2 = (XmlElement)xn1;//转换类型 

                    XmlNodeList nlss = xe2.ChildNodes;//继续获取xe2子节点的所有子节点 
                    foreach (XmlNode xn2 in nlss)//遍历 
                    {
                        if (xn2.Name == "#comment")
                        {
                            continue;
                        }
                        XmlElement xe4 = (XmlElement)xn2;//转换类型                                                                                                               
                        if ((xe4.Name == "Strategy") && ((xe4.InnerText == "Empty") || (xe4.InnerText == "empty")))//如果找到 
                        {
                            xe4.InnerText = "Editor";//则修改
                        }

                    }

                }

            }
            // xmlDoc.Save(comboBox6.Text+"//Client//BusinessObjects//ProgramInfoContainerElement//ProgramInfoContainer.dcxml");
            if (_Version == "2.0")
            {
                xmlDoc.Save(comboBox6.Text + "//DeployServer//Shared//BusinessObjects//ProgramInfoContainerElement//ProgramInfoContainer.dcxml");
            }
            else
            {
                xmlDoc.Save(comboBox6.Text + "//Client//BusinessObjects//ProgramInfoContainerElement//ProgramInfoContainer.dcxml");
            }
            xmlDoc.Load(comboBox6.Text + "//WebServer//bin//BusinessObjects//ProgramInfoContainerElement//ProgramInfoContainer.dcxml");
            nodeList = xmlDoc.SelectSingleNode("ProgramInfoContainer").ChildNodes;//获取ProgramInfoContainer节点的所有子节点 
            foreach (XmlNode xn in nodeList)//遍历所有子节点
            {
                if (xn.Name == "#comment")
                {
                    continue;
                }
                XmlElement xe = (XmlElement)xn;//将子节点类型转换为XmlElement类型 

                XmlNodeList nls = xe.ChildNodes;//继续获取xe子节点的所有子节点 
                foreach (XmlNode xn1 in nls)//遍历 
                {
                    if (xn1.Name == "#comment")
                    {
                        continue;
                    }
                    XmlElement xe2 = (XmlElement)xn1;//转换类型 

                    XmlNodeList nlss = xe2.ChildNodes;//继续获取xe2子节点的所有子节点 
                    foreach (XmlNode xn2 in nlss)//遍历 
                    {
                        if (xn2.Name == "#comment")
                        {
                            continue;
                        }
                        XmlElement xe4 = (XmlElement)xn2;//转换类型                                                                                                               
                        if ((xe4.Name == "Strategy") && ((xe4.InnerText == "Empty") || (xe4.InnerText == "empty")))//如果找到 
                        {
                            xe4.InnerText = "Editor";//则修改
                        }

                    }

                }

            }
            xmlDoc.Save(comboBox6.Text + "//WebServer//bin//BusinessObjects//ProgramInfoContainerElement//ProgramInfoContainer.dcxml");
            MessageBox.Show("修改成功");
        }

        //private void button22_Click(object sender, EventArgs e) //快速修改按钮点击事件
        //{
        //    XmlNode xmlnode;
        //    XmlNodeList nodeList;
        //    XmlElement xmlelem;
        //    XmlDocument xmlDoc=new XmlDocument();

        //    if (System.IO.File.Exists(comboBox6.Text + "//Server//AccountSetsConfiguration.xml"))
        //    {
        //        xmlDoc.Load(comboBox6.Text + "//Server//AccountSetsConfiguration.xml");
        //    }
        //    else
        //    {
        //        xmlDoc.Load(comboBox6.Text + "//Server//control//AccountSetsConfiguration.xml");
        //    }

        //    //nodeList = xmlDoc.SelectSingleNode("/AccountSetsConfigurationElement/AccountSets").ChildNodes;
        //    if (_Version == "2.0")
        //    {
        //        nodeList = xmlDoc.SelectSingleNode("/AccountSetsConfiguration/AccountSets").ChildNodes;
        //    }
        //    else
        //    {
        //        nodeList = xmlDoc.SelectSingleNode("/AccountSetsConfigurationElement/AccountSets").ChildNodes;
        //    }
        //    foreach (XmlNode xn in nodeList)
        //    {
        //        if (xn.Name == "#comment")
        //        {
        //            continue;
        //        }
        //        XmlElement xe =(XmlElement)xn;
        //        XmlNodeList nls = xe.ChildNodes;
        //        foreach (XmlNode xn1 in nls)
        //        {
        //            if (xn1.Name=="#comment")
        //            {
        //                continue;
        //            }
        //            XmlElement xe1 = (XmlElement)xn1;
        //            if ((xe1.Name == "BootType") && (xe1.InnerText == "0" || xe1.InnerText == "Auto"))//如果找到 
        //            {
        //                foreach (XmlNode xn2 in nls)
        //                {
        //                    if (xn2.Name == "#comment")
        //                    {
        //                        continue;
        //                    }
        //                    XmlElement xe2 = (XmlElement)xn2;
        //                    if (xe2.Name=="DBSetting")
        //                    {
        //                        XmlNodeList nlss = xe2.ChildNodes;
        //                        foreach (XmlNode xn3 in nlss)
        //                        {
        //                            if (xn3.Name == "#comment")
        //                            {
        //                                continue;
        //                            }
        //                            XmlElement xe3 = (XmlElement)xn3;
        //                            XmlNodeList nlsss = xe3.ChildNodes;
        //                            foreach (XmlNode xn4 in nlsss)
        //                            {
        //                                if (xn4.Name == "#comment")
        //                                {
        //                                    continue;
        //                                }
        //                                XmlElement xe4 = (XmlElement)xn4;
        //                                if (xe4.Name==("ConnectionString"))
        //                                {
        //                                    xe4.InnerText = "Data Source="+textBox40.Text+";Initial Catalog="+textBox41.Text+";User ID="+textBox42.Text+";Password="+textBox43.Text+";Pooling=true;Max Pool Size=4000";
        //                                }

        //                            }
        //                        }
        //                    }

        //                }
        //            }
        //        }
        //    }
        //    if (System.IO.File.Exists(comboBox6.Text + "//Server//AccountSetsConfiguration.xml"))
        //    {
        //        xmlDoc.Save(comboBox6.Text + "//Server//AccountSetsConfiguration.xml");
        //    }
        //    else
        //    {
        //        xmlDoc.Save(comboBox6.Text + "//Server//control//AccountSetsConfiguration.xml");
        //    }

        //    MessageBox.Show("修改成功");

        //    XmlDocument xmlDoc1=new XmlDocument();
        //    XmlDeclaration xmldecl;
        //    xmldecl = xmlDoc1.CreateXmlDeclaration("1.0", "gb2312", null);
        //    xmlDoc1.AppendChild(xmldecl);

        //    //加入一个根元素
        //    xmlelem = xmlDoc1.CreateElement("", "DataBase", "");
        //    xmlDoc1.AppendChild(xmlelem);
        //    //加入另外一个元素
        //    for (int i = 1; i < 2; i++)
        //    {

        //        XmlNode root = xmlDoc1.SelectSingleNode("DataBase");//查找<Employees> 
        //        //XmlElement xe1 = xmlDoc1.CreateElement("Node");//创建一个<Node>节点 
        //        //xe1.SetAttribute("genre", "E10");//设置该节点genre属性 

        //        XmlElement xesub1 = xmlDoc1.CreateElement("ip");
        //        xesub1.InnerText = textBox40.Text;//设置文本节点 
        //        root.AppendChild(xesub1);//添加到<Node>节点中 
        //        XmlElement xesub2 = xmlDoc1.CreateElement("catalog");
        //        xesub2.InnerText = textBox41.Text;
        //        root.AppendChild(xesub2);
        //        XmlElement xesub3 = xmlDoc1.CreateElement("user");
        //        xesub3.InnerText = textBox42.Text;
        //        root.AppendChild(xesub3);
        //        XmlElement xesub4 = xmlDoc1.CreateElement("password");
        //        xesub4.InnerText = textBox43.Text;
        //        root.AppendChild(xesub4);

        //        //root.AppendChild(xe1);//添加到<Employees>节点中 
        //    }
        //    //保存创建好的XML文档
        //    xmlDoc1.Save("database.xml");
        //    ReadConfig();

        //}


        #endregion

        #region COPY平台

        private void button11_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox2.Text = openFileDialog1.FileName;
            }
            //if (System.IO.File.Exists(str))											//判断是否存在INI文件
            //{
            //WritePrivateProfileString(strOne, "Data Source", comboBox6.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "Data Source1", textBox2.Text, str); 		//修改INI文件中服务器1节点的内容
            //WritePrivateProfileString(strOne, "Data Source2", textBox3.Text, str); 			//修改INI文件中服务器2节点的内容
            //WritePrivateProfileString(strOne, "Pwd", pwd.Text, str); 			//修改INI文件中密码节点的内容
            //MessageBox.Show("恭喜你，修改成功！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
            //else
            //{
            //    MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
        }

        private void button12_Click(object sender, EventArgs e)
        {
            if (openFileDialog2.ShowDialog() == DialogResult.OK)
            {
                textBox3.Text = openFileDialog2.FileName;
            }
            //if (System.IO.File.Exists(str))											//判断是否存在INI文件
            //{
            //WritePrivateProfileString(strOne, "Data Source", comboBox6.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "Data Source1", textBox2.Text, str); 		//修改INI文件中服务器1节点的内容
            //WritePrivateProfileString(strOne, "Data Source2", textBox3.Text, str); 			//修改INI文件中服务器2节点的内容
            //WritePrivateProfileString(strOne, "Pwd", pwd.Text, str); 			//修改INI文件中密码节点的内容
            //MessageBox.Show("恭喜你，修改成功！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
            //else
            //{
            //    MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
        }

        private void button9_Click(object sender, EventArgs e)
        {
            if (textBox2.Text.Length == 0)
            {
                MessageBox.Show("请选择原文件路径。");
                return;
            }
            fn = textBox2.Text;//记录源文件的路径
            fn = "\\" + fn.Substring(fn.LastIndexOf('\\') + 1, fn.Length - fn.LastIndexOf('\\') - 1);//获取源文件的名称
            //thdAddFile = new Thread(new ThreadStart(SetAddFile3));//创建一个线程
            //thdAddFile.Start();//执行当前线程
            System.IO.File.Copy(textBox2.Text, "d:\\" + fn.Split('.')[0] + "_E111.RAR");
            MessageBox.Show("复制完毕");
        }

        public delegate void AddFile3();//定义委托

        public void SetAddFile3()
        {
            this.Invoke(new AddFile3(RunAddFile3));//在线程上执行指定的委托
        }

        /// <summary>
        /// 对文件进行复制，并在复制完成后关闭线程
        /// </summary>
        public void RunAddFile3()
        {
            CopyFile(textBox2.Text, "d:\\" + fn, 1024, progressBar1);//复制文件
            thdAddFile.Abort();//关闭线程
        }

        private void button25_Click(object sender, EventArgs e)
        {
            fn = textBox2.Text;//记录源文件的路径
            fn = "\\" + fn.Substring(fn.LastIndexOf('\\') + 1, fn.Length - fn.LastIndexOf('\\') - 1);//获取源文件的名称
            Process.Start("d:\\" + fn.Split('.')[0] + "_E111.RAR");
        }

        private void button10_Click(object sender, EventArgs e)
        {
            if (textBox3.Text.Length == 0)
            {
                MessageBox.Show("请选择原文件路径。");
                return;
            }
            fn = textBox3.Text;//记录源文件的路径
            fn = "\\" + fn.Substring(fn.LastIndexOf('\\') + 1, fn.Length - fn.LastIndexOf('\\') - 1);//获取源文件的名称
            //thdAddFile = new Thread(new ThreadStart(SetAddFile4));//创建一个线程
            //thdAddFile.Start();//执行当前线程
            System.IO.File.Copy(textBox3.Text, "d:\\" + fn.Split('.')[0] + "_E20.RAR");
            MessageBox.Show("复制完毕");
        }

        public void SetAddFile4()
        {
            this.Invoke(new AddFile4(RunAddFile4));//在线程上执行指定的委托
        }
        public delegate void AddFile4();//定义委托
        /// <summary>
        /// 对文件进行复制，并在复制完成后关闭线程
        /// </summary>
        public void RunAddFile4()
        {
            CopyFile(textBox3.Text, "d:\\" + fn, 1024, progressBar1);//复制文件
            thdAddFile.Abort();//关闭线程
        }

        private void button26_Click(object sender, EventArgs e)
        {
            fn = textBox3.Text;//记录源文件的路径
            fn = "\\" + fn.Substring(fn.LastIndexOf('\\') + 1, fn.Length - fn.LastIndexOf('\\') - 1);//获取源文件的名称
            Process.Start("d:\\" + fn.Split('.')[0] + "_E20.RAR");
        }

        #endregion

        #region 1.1.1 client

        private void button33_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox21.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox21.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application 1.1.1UC";
            shortcut.Arguments = "/L";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //Thread.Sleep(_SEC);
            //login("", textBox34.Text);
            Record_MWH("1");
        }

        private void button17_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox21.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox21.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application 1.1.1UC";
            shortcut.Arguments = "";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //Thread.Sleep(_SEC);
            //login("", textBox34.Text);
            Record_MWH("1");
        }

        #endregion

        #region CM client

        private void button81_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox25.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox25.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application UCM";
            shortcut.Arguments = "";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //    Thread.Sleep(_SEC);
            //    login("", textBox32.Text);
            Record_MWH("0");
        }
        private void button23_Click(object sender, EventArgs e)
        {
            string Arg = "";
            if (checkBox7.Checked)
            {
                Arg += "/L ";
            }

            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox25.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox25.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application UCM";
            shortcut.Arguments = Arg;
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //    Thread.Sleep(_SEC);
            //    login("", textBox32.Text);
            Record_MWH("0");
            //copyDirectory(textBox53.Text, textBox25.Text);
            System.IO.File.Copy(@textBox53.Text, textBox25.Text+ "\\Customization\\BusinessObjects\\ISSUE\\FormulaContainer.dcxml", true);
        }
        private void button80_Click(object sender, EventArgs e)
        {
            Process[] ps = Process.GetProcesses();
            foreach (Process item in ps)
            {
                if (item.ProcessName == "Digiwin.Mars.ClientStart")
                {
                    foreach (string s in R)
                    {
                        if (s == null)
                        {
                            break;
                        }
                        string[] sp = s.Split('.');
                        if (sp[1] == "0" && sp[0].Equals(item.Id.ToString()))
                        {
                            item.Kill();
                        }
                    }
                }
            }
        }
        //记录MainWindowHandle
        private void Record_MWH(string s)
        {
            string _s = s;
            Process[] ps = Process.GetProcesses();
            foreach (Process item in ps)
            {
                if (item.ProcessName == "Digiwin.Mars.ClientStart")
                {
                    bool b = true;
                    if (R[0] != null)
                    {
                        foreach (string t in R)
                        {
                            if (t == null)
                            {
                                break;
                            }
                            string[] sp = t.Split('.');
                            if (sp[0].Equals(item.Id.ToString()))
                            {
                                b = false;
                            }
                        }
                        if (b)
                        {
                            R[i] = item.Id.ToString() + "." + _s;
                            i++;
                        }
                    }
                    else
                    {
                        R[i] = item.Id.ToString() + "." + _s;
                        i++;
                    }
                }
            }
        }

        #endregion

        #region 2.0 client
        private void button1_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox22.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox22.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application 2.0UC";
            shortcut.Arguments = "/L";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //Thread.Sleep(_SEC);
            //login("", textBox35.Text);
            Record_MWH("1");
        }

        private void button13_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox22.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox22.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application 2.0UC";
            shortcut.Arguments = "";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //Thread.Sleep(_SEC);
            //login("", textBox35.Text);
            Record_MWH("1");
        }

        #endregion

        #region HJ client

        private void button19_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox23.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox23.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application HJ UC";
            shortcut.Arguments = "/L";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //Thread.Sleep(_SEC);
            //login("", textBox36.Text);
            Record_MWH("1");
        }

        private void button20_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox23.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox23.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application HJ UC";
            shortcut.Arguments = "";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //Thread.Sleep(_SEC);
            //login("", textBox36.Text);
            Record_MWH("1");
        }

        #endregion

        #region 2.0.1

        private void button14_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox24.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox24.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application 2.0.1 UC";
            shortcut.Arguments = "/L";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //Thread.Sleep(_SEC);
            //login("", textBox37.Text);
            Record_MWH("1");
        }

        private void button16_Click(object sender, EventArgs e)
        {
            WshShell shell = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("C:\\Windows\\Temp" +
     "\\" + "Digiwin.Mars.Deployment.Client.exe - 快捷方式.lnk");
            shortcut.TargetPath = textBox24.Text + "\\Digiwin.Mars.Deployment.Client.exe";
            shortcut.WorkingDirectory = textBox24.Text;
            shortcut.WindowStyle = 1;
            shortcut.Description = "Launch Patrick’s Application 2.0.1 UC";
            shortcut.Arguments = "";
            shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
            shortcut.Save();
            Process.Start("C:\\Windows\\Temp\\Digiwin.Mars.Deployment.Client.exe - 快捷方式");
            //Thread.Sleep(_SEC);
            //login("", textBox37.Text);
            Record_MWH("1");
        }

        #endregion

        #region 快捷按钮

        //private void button27_Click(object sender, EventArgs e)
        //{
        //    Process.Start(textBox11.Text +"\\TinderDesignerShell.exe");           
        //}

        //private void button28_Click(object sender, EventArgs e)
        //{
        //    Process.Start(textBox13.Text + "\\Ssms.exe"); 
        //}

        //private void button29_Click(object sender, EventArgs e)
        //{
        //    Process.Start(textBox14.Text + "\\devenv.exe");
        //}

        //private void button30_Click(object sender, EventArgs e)
        //{
        //    Process.Start(textBox12.Text + "\\SimpleUpdater.exe");
        //}

        //private void button36_Click(object sender, EventArgs e)
        //{
        //    Process.Start(textBox18.Text + "\\ExtensionToPatch.exe");
        //}

        //private void button37_Click(object sender, EventArgs e)
        //{
        //    Process.Start(textBox17.Text + "\\Seraphim.KanoMatrix.exe");
        //}

        //private void button38_Click(object sender, EventArgs e)
        //{
        //    Process.Start(textBox16.Text + "\\Merge.exe");
        //}

        //private void button39_Click(object sender, EventArgs e)
        //{
        //    Process.Start(textBox15.Text + "\\Reflector.exe");
        //}

        private void button56_Click(object sender, EventArgs e)  //启动IIS
        {
            Process.Start("C:\\Windows\\system32\\inetsrv\\InetMgr.exe");
        }

        //private void button57_Click(object sender, EventArgs e) //关闭设计器
        //{
        //    Process[] ps = Process.GetProcesses();
        //    foreach (Process item in ps)
        //    {
        //        if (item.ProcessName == "TinderDesignerShell")
        //        {
        //            item.Kill();
        //        }
        //    }
        //}

        //private void button58_Click(object sender, EventArgs e) //重启IIS
        //{
        //    Process.Start("C:\\Windows\\System32\\iisreset.exe");
        //}

        //private void button82_Click(object sender, EventArgs e)
        //{
        //    Process.Start("\\\\172.16.1.121\\");
        //}

        //private void button83_Click(object sender, EventArgs e)
        //{
        //    Process.Start("\\\\172.16.1.29\\");
        //}

        //private void button85_Click(object sender, EventArgs e)
        //{
        //    Process.Start("\\\\172.16.1.244\\");
        //}

        //private void button86_Click(object sender, EventArgs e)
        //{
        //    Process.Start("\\\\172.16.1.45\\");
        //}

        //private void button87_Click(object sender, EventArgs e)
        //{
        //    Process.Start("\\\\172.16.1.204\\");
        //}

        //private void button88_Click(object sender, EventArgs e)
        //{
        //    Process.Start("\\\\192.168.9.10\\");
        //}

        //private void button84_Click(object sender, EventArgs e)
        //{
        //    Process.Start("\\\\192.168.9.22\\");
        //}
        #endregion

        #region DLL处理

        private void button54_Click(object sender, EventArgs e)
        {
            string newName;
            //comboBox6.Text = folderBrowserDialog1.SelectedPath;
            //实例化DirectoryInfo对象
            DirectoryInfo dinfo = new DirectoryInfo(textBox6.Text);
            //获取指定目录下的所有子目录及文件类型
            FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
            foreach (FileSystemInfo fsinfo in fsinfos)
            {
                if (fsinfo is DirectoryInfo)    //判断是否文件夹
                {

                }
                else
                {
                    if (fsinfo.FullName.Substring(
                fsinfo.FullName.LastIndexOf(".") + 1,
                fsinfo.FullName.Length -
                fsinfo.FullName.LastIndexOf(".") - 1) == "重命名")
                    {
                        System.IO.File.Move(fsinfo.FullName, fsinfo.FullName.Remove(fsinfo.FullName.LastIndexOf(".") + 1));
                        newName = fsinfo.Name.Remove(fsinfo.Name.LastIndexOf(".") + 1);
                        System.IO.File.Copy(fsinfo.FullName.Remove(fsinfo.FullName.LastIndexOf(".") + 1), textBox23.Text + "\\DF_E10_2.0\\WD_PR\\SRC\\Export\\" + newName, true);
                    }
                }
            }
        }

        private void button40_Click(object sender, EventArgs e)
        {
            checkedListBox1.Items.Clear();

            //comboBox6.Text = folderBrowserDialog1.SelectedPath;
            //实例化DirectoryInfo对象
            DirectoryInfo dinfo = null;
            if (comboBoxproduct.Text == "CM_1.1")
            {
                if (!Directory.Exists(textBox23.Text + "\\DF_CM_1.1\\WD_PR\\SRC\\Export"))
                {
                    Directory.CreateDirectory(textBox23.Text + "\\DF_CM_1.1\\WD_PR\\SRC\\Export");
                }
                dinfo = new DirectoryInfo(textBox23.Text + "\\DF_CM_1.1\\WD_PR\\SRC\\Export");
            }
            if (comboBoxproduct.Text == "DS_1.0")
            {
                if (!Directory.Exists(textBox23.Text + "\\DF_DS_1.0\\WD_PR\\SRC\\Export"))
                {
                    Directory.CreateDirectory(textBox23.Text + "\\DF_DS_1.0\\WD_PR\\SRC\\Export");
                }
                dinfo = new DirectoryInfo(textBox23.Text + "\\DF_DS_1.0\\WD_PR\\SRC\\Export");
            }
            if (comboBoxproduct.Text == "E10_2.0")
            {
                if (!Directory.Exists(textBox23.Text + "\\DF_E10_2.0\\WD_PR\\SRC\\Export"))
                {
                    Directory.CreateDirectory(textBox23.Text + "\\DF_E10_2.0\\WD_PR\\SRC\\Export");
                }
                dinfo = new DirectoryInfo(textBox23.Text + "\\DF_E10_2.0\\WD_PR\\SRC\\Export");
            }
            if (comboBoxproduct.Text == "E10_1.1.1")
            {
                if (!Directory.Exists(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR\\SRC\\Export"))
                {
                    Directory.CreateDirectory(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR\\SRC\\Export");
                }
                dinfo = new DirectoryInfo(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR\\SRC\\Export");
            }
            if (comboBoxproduct.Text == "E10_1.1.1_B")
            {
                if (!Directory.Exists(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR\\SRC\\Export"))
                {
                    Directory.CreateDirectory(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR\\SRC\\Export");
                }
                dinfo = new DirectoryInfo(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR\\SRC\\Export");
            }
            if (comboBoxproduct.Text == "E10_ALEX111")
            {
                if (!Directory.Exists(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_ALEX\\SRC\\Export"))
                {
                    Directory.CreateDirectory(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_ALEX\\SRC\\Export");
                }
                dinfo = new DirectoryInfo(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_ALEX\\SRC\\Export");
            }
            if (comboBoxproduct.Text == "E10_HJDZ111")
            {
                if (!Directory.Exists(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_HJDZ\\SRC\\Export"))
                {
                    Directory.CreateDirectory(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_HJDZ\\SRC\\Export");
                }
                dinfo = new DirectoryInfo(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_HJDZ\\SRC\\Export");
            }
            if (comboBoxproduct.Text == "E10_NBXL111")
            {
                if (!Directory.Exists(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_NBXL\\SRC\\Export"))
                {
                    Directory.CreateDirectory(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_NBXL\\SRC\\Export");
                }
                dinfo = new DirectoryInfo(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_NBXL\\SRC\\Export");
            }
            if (comboBoxproduct.Text == "E10_QTDG111")
            {
                if (!Directory.Exists(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_QTDG\\SRC\\Export"))
                {
                    Directory.CreateDirectory(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_QTDG\\SRC\\Export");
                }
                dinfo = new DirectoryInfo(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_QTDG\\SRC\\Export");
            }
            if (comboBoxproduct.Text == "E10_TCV111")
            {
                if (!Directory.Exists(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_TCV\\SRC\\Export"))
                {
                    Directory.CreateDirectory(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_TCV\\SRC\\Export");
                }
                dinfo = new DirectoryInfo(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_TCV\\SRC\\Export");
            }
            if (comboBoxproduct.Text == "E10_WJBZ111")
            {
                if (!Directory.Exists(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_WJBZ\\SRC\\Export"))
                {
                    Directory.CreateDirectory(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_WJBZ\\SRC\\Export");
                }
                dinfo = new DirectoryInfo(textBox23.Text + "\\DF_E10_1.1.1\\WD_PR_C_WJBZ\\SRC\\Export");
            }
            if (comboBoxproduct.Text == "E10_BAKE20")
            {
                if (!Directory.Exists(textBox23.Text + "\\DF_E10_2.0\\WD_PR_I_BAKE\\SRC\\Export"))
                {
                    Directory.CreateDirectory(textBox23.Text + "\\DF_E10_2.0\\WD_PR_I_BAKE\\SRC\\Export");
                }
                dinfo = new DirectoryInfo(textBox23.Text + "\\DF_E10_2.0\\WD_PR_I_BAKE\\SRC\\Export");
            }
            if (comboBoxproduct.Text == "SRMS_2.0")
            {
                if (!Directory.Exists(textBox23.Text + "\\DF_E10_2.0\\WD_PR\\SRC\\Export"))
                {
                    Directory.CreateDirectory(textBox23.Text + "\\DF_E10_2.0\\WD_PR\\SRC\\Export");
                }
                dinfo = new DirectoryInfo(textBox23.Text + "\\DF_E10_2.0\\WD_PR\\SRC\\Export");
            }
            if (comboBoxproduct.Text == "SRMS_BAKE20")
            {
                if (!Directory.Exists(textBox23.Text + "\\DF_E10_2.0\\WD_PR_I_BAKE\\SRC\\Export"))
                {
                    Directory.CreateDirectory(textBox23.Text + "\\DF_E10_2.0\\WD_PR_I_BAKE\\SRC\\Export");
                }
                dinfo = new DirectoryInfo(textBox23.Text + "\\DF_E10_2.0\\WD_PR_I_BAKE\\SRC\\Export");
            }
            //获取指定目录下的所有子目录及文件类型
            FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
            FileSystemInfo temp;
            bool flag = true;
            for (int i = fsinfos.Length - 1; i >= 0 && flag; i--)
            {
                flag = false;                                    //改进就在这里，当不再比较的时候flag就不会设置为true，停止排序
                for (int j = 0; j < i; j++)
                {

                    if (fsinfos[j].LastWriteTime < fsinfos[j + 1].LastWriteTime)
                    {

                        flag = true;
                        temp = fsinfos[j];
                        fsinfos[j] = fsinfos[j + 1];
                        fsinfos[j + 1] = temp;
                    }
                }
            }
            foreach (FileSystemInfo fsinfo in fsinfos)
            {
                if (fsinfo is DirectoryInfo)    //判断是否文件夹
                {
                    //使用获取的文件夹名称实例化DirectoryInfo对象
                    //DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                    //为ListView控件添加文件夹信息
                    //checkedListBox1.Items.Add("abc");
                    //listView1.Items[listView1.Items.Count - 1].SubItems.Add(dirinfo.FullName);
                    //listView1.Items[listView1.Items.Count - 1].SubItems.Add("");
                    //listView1.Items[listView1.Items.Count - 1].SubItems.Add(dirinfo.CreationTime.ToShortDateString());
                }
                else
                {
                    if (fsinfo.FullName.Substring(
                fsinfo.FullName.LastIndexOf(".") + 1,
                fsinfo.FullName.Length -
                fsinfo.FullName.LastIndexOf(".") - 1) == "dll")
                    {
                        //使用获取的文件名称实例化FileInfo对象
                        FileInfo finfo = new FileInfo(fsinfo.FullName);
                        //为ListView控件添加文件信息
                        checkedListBox1.Items.Add(finfo.Name);
                        //listView1.Items[listView1.Items.Count - 1].SubItems.Add(finfo.FullName);
                        //listView1.Items[listView1.Items.Count - 1].SubItems.Add(finfo.Length.ToString());
                        //listView1.Items[listView1.Items.Count - 1].SubItems.Add(finfo.CreationTime.ToShortDateString());
                    }
                }
            }

        }

        private void button41_Click(object sender, EventArgs e)
        {
            if (checkedListBox1.CheckedItems.Count != 0)
            {
                Process[] ps = Process.GetProcesses();
                foreach (Process item in ps)
                {
                    if (item.ProcessName == "Digiwin.Mars.ServerStart")
                    {
                        item.Kill();
                    }
                }

                FileInfo f;
                for (int x = 0; x <= checkedListBox1.CheckedItems.Count - 1; x++)
                {
                    f = new FileInfo(textBox23.Text + "\\DF_E10_2.0\\WD_PR\\SRC\\Export\\" + checkedListBox1.CheckedItems[x].ToString());
                    f.CopyTo(comboBox6.Text + "\\Server\\Programs\\" + checkedListBox1.CheckedItems[x].ToString(), true);
                }
                MessageBox.Show("复制到Server OK");
            }

        }

        private void button42_Click(object sender, EventArgs e)
        {
            if (checkedListBox1.CheckedItems.Count != 0)
            {
                // If so, loop through all checked items and print results.

                FileInfo f;
                for (int x = 0; x <= checkedListBox1.CheckedItems.Count - 1; x++)
                {
                    f = new FileInfo(textBox23.Text + "\\DF_E10_2.0\\WD_PR\\SRC\\Export\\" + checkedListBox1.CheckedItems[x].ToString());
                    f.CopyTo(comboBox6.Text + "\\Client\\Programs\\" + checkedListBox1.CheckedItems[x].ToString(), true);
                }
                MessageBox.Show("复制到Client OK");
            }
        }

        private void button52_Click(object sender, EventArgs e)
        {
            Process.Start(textBox23.Text + "\\DF_E10_2.0\\WD_PR\\SRC\\Export");
        }

        #endregion

        #region 提取平台文件


        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadType();
            if (comboBox2.Items.Count > 0)
            {
                comboBox2.Text = comboBox2.Items[0].ToString();
            }
            else
            {
                comboBox2.Text = "";
            }

            //Dir_Load(comboBoxproduct1, comboBox1, comboBox2);
            dir_pick = dir;
        }

        private void Dir_Load(ComboBox comboBoxP, ComboBox comboBoxT, ComboBox comboBoxC)
        {
            comboBoxC.Items.Clear();
            try
            {
                string sql = "SELECT GET_FOLDER_LAST FROM dbo.PRODUCT_GROUP WHERE PRODUCT_GROUP_CODE='" + comboBoxP.Text + "'";
                SqlCommand cmd = new SqlCommand(sql, conn);
                string str1 = Convert.ToString(cmd.ExecuteScalar());
                string Tempdir = "";
                string Tempdir1 = "\\WD" + str1;

                if (comboBoxP.Text.ToString().Contains("20") | comboBoxP.Text.ToString().Contains("2.0"))
                {
                    Tempdir = textBox23.Text + "\\DF_E10_2.0";
                }
                if (comboBoxP.Text.ToString().Contains("111") | comboBoxP.Text.ToString().Contains("1.1.1"))
                {
                    Tempdir = textBox23.Text + "\\DF_E10_1.1.1";
                }
                if (comboBoxP.Text.ToString().Contains("201") | comboBoxP.Text.ToString().Contains("2.0.1"))
                {
                    Tempdir = textBox23.Text + "\\DF_E10_2.0.1";
                }
                if (comboBoxP.Text == "DS_1.0")
                {
                    Tempdir = textBox23.Text + "\\DF_DS_1.0";
                    return;
                }
                if (comboBoxP.Text == "CM_1.1")
                {
                    Tempdir = textBox23.Text + "\\DF_CM_1.1";
                    return;
                }


                if (comboBoxT.Text == "Designer Project")
                {
                    DirectoryInfo dinfo = new DirectoryInfo(Tempdir + Tempdir1 + "\\businessobjects\\");
                    dir = dinfo.FullName;
                    //获取指定目录下的所有子目录及文件类型
                    FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
                    foreach (FileSystemInfo fsinfo in fsinfos)
                    {
                        if (fsinfo is DirectoryInfo)    //判断是否文件夹
                        {
                            //使用获取的文件夹名称实例化DirectoryInfo对象
                            DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                            //为ListView控件添加文件夹信息
                            comboBoxC.Items.Add(dirinfo.Name);

                        }

                    }
                }

                if (comboBoxT.Text == "Report Project")
                {
                    DirectoryInfo dinfo = new DirectoryInfo(Tempdir + Tempdir1 + "\\ReportObjects\\");
                    dir = dinfo.FullName;
                    //获取指定目录下的所有子目录及文件类型
                    FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
                    foreach (FileSystemInfo fsinfo in fsinfos)
                    {
                        if (fsinfo is DirectoryInfo)    //判断是否文件夹
                        {
                            //使用获取的文件夹名称实例化DirectoryInfo对象
                            DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                            //为ListView控件添加文件夹信息
                            comboBoxC.Items.Add(dirinfo.Name);

                        }

                    }
                }
                if (comboBoxT.Text == "Batch Project")
                {
                    DirectoryInfo dinfo = new DirectoryInfo(Tempdir + Tempdir1 + "\\BatchObjects\\");
                    dir = dinfo.FullName;
                    //获取指定目录下的所有子目录及文件类型
                    FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
                    foreach (FileSystemInfo fsinfo in fsinfos)
                    {
                        if (fsinfo is DirectoryInfo)    //判断是否文件夹
                        {
                            //使用获取的文件夹名称实例化DirectoryInfo对象
                            DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                            //为ListView控件添加文件夹信息
                            comboBoxC.Items.Add(dirinfo.Name);

                        }

                    }
                }
                if (comboBoxT.Text == "DataModel Project")
                {
                    DirectoryInfo dinfo = new DirectoryInfo(Tempdir + Tempdir1 + "\\DataModels\\");
                    dir = dinfo.FullName;
                    //获取指定目录下的所有子目录及文件类型
                    FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
                    foreach (FileSystemInfo fsinfo in fsinfos)
                    {
                        if (fsinfo is DirectoryInfo)    //判断是否文件夹
                        {
                            //使用获取的文件夹名称实例化DirectoryInfo对象
                            DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                            //为ListView控件添加文件夹信息
                            comboBoxC.Items.Add(dirinfo.Name);

                        }

                    }
                }
                if (comboBoxT.Text == "ValidatorSnippet Project")
                {
                    return;
                }
                if (comboBoxC.Items.Count > 0)
                {
                    comboBoxC.Text = comboBoxC.Items[0].ToString();
                }
                else
                {
                    comboBoxC.Text = "";
                }
            }
            catch
            {
                MessageBox.Show(comboBoxP.Text + "网络连接失败或在映射盘没有建立目录！");
            }
        }

        //private void button49_Click(object sender, EventArgs e)
        //{
        //    Process.Start(dir);
        //}

        //private void button43_Click(object sender, EventArgs e)
        //{
        //    if (MessageBox.Show("是否删除" + comboBox2.Text, "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
        //    {
        //        DirectoryInfo d = new DirectoryInfo(dir + comboBox2.Text);
        //        d.Delete(true);
        //        MessageBox.Show("ok!!!");
        //    }

        //}

        private void button59_Click(object sender, EventArgs e) //提取环境文件
        {
            PickType();
            //string tempDir = "\\Client", tempDir1 = "\\Server", tempDir2 = "";
            ////if (comboBoxproduct1.Text != "E10_2.0" & comboBoxproduct1.Text != "E10_1.1.1" &
            ////    comboBoxproduct1.Text != "CM_1.1" & comboBoxproduct1.Text != "DS_1.0" &
            ////    comboBoxproduct1.Text != "E10_1.1.1_B" & comboBoxproduct1.Text != "SRMS_2.0" &
            ////    comboBoxproduct1.Text != "SRMS_BAKE20" & comboBoxproduct1.Text != "E10_HJDZ20")
            ////{
            ////    tempDir = "\\Client\\Customization";
            ////    tempDir1 = "\\Server\\Customization";
            ////    tempDir2 = "\\Customization";
            ////    Directory.CreateDirectory(textBox6.Text + "\\平台文件");
            ////    Directory.CreateDirectory(textBox6.Text + "\\平台文件" + tempDir + "\\Programs\\");
            ////    Directory.CreateDirectory(textBox6.Text + "\\平台文件" + tempDir1 + "\\Programs\\");
            ////}
            ////else
            ////{
            ////    if (comboBoxproduct1.Text == "E10_2.0")
            ////    {
            ////        tempDir = "\\DeployServer\\Shared";
            ////        tempDir1 = "\\Server\\Application";
            ////    }
            ////    if (comboBoxproduct1.Text == "E10_HJDZ20")
            ////    {
            ////        tempDir = "\\DeployServer\\Shared\\Customization";
            ////        tempDir1 = "\\Server\\Application\\Customization";
            ////        tempDir2 = "\\Customization";
            ////    }
            ////    Directory.CreateDirectory(textBox6.Text + "\\平台文件");
            ////    Directory.CreateDirectory(textBox6.Text + "\\平台文件" + tempDir + "\\Programs\\");
            ////    Directory.CreateDirectory(textBox6.Text + "\\平台文件" + tempDir1 + "\\Programs\\");
            ////}

            //if (comboBoxproduct1.Text.ToString().Contains("2.0") | comboBoxproduct1.Text.ToString().Contains("2.0.1") | comboBoxproduct1.Text.ToString().Contains("1.1"))
            //{
            //    tempDir = "\\DeployServer\\Shared";
            //    tempDir1 = "\\Server\\Application";
            //}
            //else if (comboBoxproduct1.Text.ToString().Contains("20") | comboBoxproduct1.Text.ToString().Contains("201"))
            //{
            //    tempDir = "\\DeployServer\\Shared";
            //    tempDir1 = "\\Server\\Application";
            //    tempDir2 = "\\Customization";
            //}
            //else if (comboBoxproduct1.Text.ToString().Contains("111"))
            //{
            //    tempDir2 = "\\Customization";
            //}
            //Directory.CreateDirectory(textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text);
            //Directory.CreateDirectory(textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + tempDir + "\\Programs\\");
            //Directory.CreateDirectory(textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + tempDir1 + "\\Programs\\");
            //Directory.CreateDirectory(textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + tempDir1 + "\\BusinessObjects\\DataModel\\");

            //DirectoryInfo dinfo = new DirectoryInfo(comboBox6.Text + tempDir1 + "\\Programs");
            //FileSystemInfo[] fsinfos;
            //FileSystemInfo temp;
            //bool flag;
            //if (Directory.Exists(dinfo.ToString()))
            //{
            //    //获取指定目录下的所有子目录及文件类型
            //    fsinfos = dinfo.GetFileSystemInfos();
            //    flag = true;
            //    for (int i = fsinfos.Length - 1; i >= 0 && flag; i--)
            //    {
            //        flag = false;                                    //改进就在这里，当不再比较的时候flag就不会设置为true，停止排序
            //        for (int j = 0; j < i; j++)
            //        {

            //            if (fsinfos[j].LastWriteTime < fsinfos[j + 1].LastWriteTime)
            //            {

            //                flag = true;
            //                temp = fsinfos[j];
            //                fsinfos[j] = fsinfos[j + 1];
            //                fsinfos[j + 1] = temp;
            //            }
            //        }
            //    }
            //    foreach (FileSystemInfo fsinfo in fsinfos)
            //    {

            //        if (fsinfo is DirectoryInfo)    //判断是否文件夹
            //        {

            //        }
            //        else
            //        {
            //            string[] sp = fsinfo.Name.Split('.');
            //            if (sp[0].Equals("Digiwin"))
            //            {
            //                if ((sp[2].Length == comboBox2.Text.Length) && fsinfo.Name.Substring(12, comboBox2.Text.Length).Equals(comboBox2.Text))
            //                {
            //                    System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + tempDir1 + "\\Programs\\" + fsinfo.Name, true);
            //                }
            //                if ((comboBoxproduct1.Text != "E10_2.0" & comboBoxproduct1.Text != "E10_1.1.1" &
            //    comboBoxproduct1.Text != "CM_1.1" & comboBoxproduct1.Text != "DS_1.0" &
            //    comboBoxproduct1.Text != "E10_1.1.1_B" & comboBoxproduct1.Text != "SRMS_2.0" &
            //    comboBoxproduct1.Text != "SRMS_BAKE20") && (sp[2].Length) - 2 == comboBox2.Text.Length && fsinfo.Name.Substring(14, comboBox2.Text.Length).Equals(comboBox2.Text))
            //                {
            //                    System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + tempDir1 + "\\Programs\\" + fsinfo.Name, true);
            //                }

            //            }
            //        }

            //    }
            //}
            //dinfo = new DirectoryInfo(comboBox6.Text + tempDir + "\\Programs");
            //if (Directory.Exists(dinfo.ToString()))
            //{
            //    //获取指定目录下的所有子目录及文件类型
            //    fsinfos = dinfo.GetFileSystemInfos();
            //    flag = true;
            //    for (int i = fsinfos.Length - 1; i >= 0 && flag; i--)
            //    {
            //        flag = false;                                    //改进就在这里，当不再比较的时候flag就不会设置为true，停止排序
            //        for (int j = 0; j < i; j++)
            //        {

            //            if (fsinfos[j].LastWriteTime < fsinfos[j + 1].LastWriteTime)
            //            {

            //                flag = true;
            //                temp = fsinfos[j];
            //                fsinfos[j] = fsinfos[j + 1];
            //                fsinfos[j + 1] = temp;
            //            }
            //        }
            //    }
            //    foreach (FileSystemInfo fsinfo in fsinfos)
            //    {

            //        if (fsinfo is DirectoryInfo)    //判断是否文件夹
            //        {

            //        }
            //        else
            //        {
            //            string[] sp = fsinfo.Name.Split('.');
            //            if (sp[0].Equals("Digiwin"))
            //            {

            //                if (fsinfo.Name.Substring(12, sp[2].Length).Equals(comboBox2.Text))
            //                {
            //                    System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + tempDir + "\\Programs\\" + fsinfo.Name, true);
            //                }
            //                if ((comboBoxproduct1.Text != "E10_2.0" & comboBoxproduct1.Text != "E10_1.1.1" &
            //    comboBoxproduct1.Text != "CM_1.1" & comboBoxproduct1.Text != "DS_1.0" &
            //    comboBoxproduct1.Text != "E10_1.1.1_B" & comboBoxproduct1.Text != "SRMS_2.0" &
            //    comboBoxproduct1.Text != "SRMS_BAKE20") && fsinfo.Name.Substring(14, sp[2].Length).Equals(comboBox2.Text))
            //                {
            //                    System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + tempDir + "\\Programs\\" + fsinfo.Name, true);
            //                }
            //            }
            //        }

            //    }
            //}

            //if (comboBox1.Text == "Designer Project")
            //{
            //    copyDirectory(comboBox6.Text + tempDir + "\\BusinessObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + tempDir + "\\BusinessObjects\\" + comboBox2.Text);
            //    copyDirectory(comboBox6.Text + tempDir1 + "\\BusinessObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + tempDir1 + "\\BusinessObjects\\" + comboBox2.Text);
            //    copyDirectory(comboBox6.Text + tempDir + "\\BusinessObjects\\ProgramInfoContainerElement", textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + tempDir + "\\BusinessObjects\\ProgramInfoContainerElement");

            //    MessageBox.Show("提取" + comboBox2.Text + "完成");
            //}
            //if (comboBox1.Text == "Report Project")
            //{
            //    copyDirectory(comboBox6.Text + tempDir1 + "\\ReportObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + tempDir1 + "\\ReportObjects\\" + comboBox2.Text);
            //    copyDirectory(comboBox6.Text + "\\Webserver\\bin" + tempDir2 + "\\ReportObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + "\\Webserver\\bin" + tempDir2 + "\\ReportObjects\\" + comboBox2.Text);
            //    copyDirectory(comboBox6.Text + tempDir + "\\BusinessObjects\\ProgramInfoContainerElement", textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + tempDir + "\\BusinessObjects\\ProgramInfoContainerElement");

            //    MessageBox.Show("提取" + comboBox2.Text + "完成");
            //}
            //if (comboBox1.Text == "Batch Project")
            //{
            //    copyDirectory(comboBox6.Text + tempDir + "\\BatchObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + tempDir + "\\BatchObjects\\" + comboBox2.Text);
            //    copyDirectory(comboBox6.Text + tempDir1 + "\\BatchObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + tempDir1 + "\\BatchObjects\\" + comboBox2.Text);
            //    copyDirectory(comboBox6.Text + tempDir + "\\BusinessObjects\\ProgramInfoContainerElement", textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + tempDir + "\\BusinessObjects\\ProgramInfoContainerElement");

            //    MessageBox.Show("提取" + comboBox2.Text + "完成");
            //}
            //if (comboBox1.Text == "DataModel Project")
            //{
            //    System.IO.File.Copy(comboBox6.Text + tempDir1 + "\\BusinessObjects\\DataModel\\DataModel." + comboBox2.Text + ".dcxml", textBox6.Text + "\\平台文件\\" + comboBoxproduct1.Text + tempDir1 + "\\BusinessObjects\\DataModel\\DataModel." + comboBox2.Text + ".dcxml", true);
            //    MessageBox.Show("提取" + comboBox2.Text + "完成");
            //}
        }

        private string[] PanduanVersion(string path)
        {
            string[] pt = new string[10];//0:server路径  1：client路径  2：二次开发server路径 3：二次开发client路径 4：报表server  5：报表client 6：报表二次开发server 7：报表二次开发client 8:DM 9：DM二次开发
            string sql = "SELECT PLATFORM_VERSION FROM dbo.PRODUCT_GROUP WHERE PRODUCT_GROUP_CODE='" + comboBoxproduct2.Text + "'";
            SqlCommand cmd = new SqlCommand(sql, conn);
            string str1 = Convert.ToString(cmd.ExecuteScalar());
            if (Directory.Exists(path + "\\DeployServer\\"))
            {
                if (str1 == "1.6")
                {
                    if (Directory.Exists(path + "\\Server\\"))
                    {
                        pt[0] = "\\Server\\";
                        pt[1] = "\\Client\\";
                        pt[4] = "\\Server\\ReportObjects\\";
                        pt[5] = "\\WebServer\\bin\\";
                        pt[8] = "\\Server\\BusinessObjects\\DataModel\\";
                        if (Directory.Exists(path + "\\Server\\Customization\\"))
                        {
                            pt[2] = "\\Server\\Customization\\";
                        }
                        else
                        {
                            pt[2] = "";
                        }
                        if (Directory.Exists(path + "\\Client\\Customization\\"))
                        {
                            pt[3] = "\\Client\\Customization\\";
                        }
                        else
                        {
                            pt[3] = "";
                        }
                        if (Directory.Exists(path + "\\Server\\Customization\\ReportObjects\\"))
                        {
                            pt[6] = "\\Server\\Customization\\ReportObjects\\";
                        }
                        else
                        {
                            pt[6] = "";
                        }
                        if (Directory.Exists(path + "\\WebServer\\bin\\Customization\\"))
                        {
                            pt[7] = "\\WebServer\\bin\\Customization\\";
                        }
                        else
                        {
                            pt[7] = "";
                        }
                        if (Directory.Exists(path + "\\Server\\Customization\\BusinessObjects\\DataModel\\"))
                        {
                            pt[9] = "\\Server\\Customization\\BusinessObjects\\DataModel\\";
                        }
                        else
                        {
                            pt[9] = "";
                        }
                    }

                }
                else
                {
                    pt[0] = "\\Server\\Application\\";
                    pt[1] = "\\DeployServer\\Shared\\";
                    pt[4] = "\\Server\\Application\\ReportObjects\\";
                    pt[5] = "\\WebServer\\bin\\";
                    pt[8] = "\\Server\\Application\\BusinessObjects\\DataModel\\";
                    if (Directory.Exists(path + "\\Server\\Application\\Customization\\"))
                    {
                        pt[2] = "\\Server\\Application\\Customization\\";
                    }
                    else
                    {
                        pt[2] = "";
                    }
                    if (Directory.Exists(path + "\\DeployServer\\Shared\\Customization\\"))
                    {
                        pt[3] = "\\DeployServer\\Shared\\Customization\\";
                    }
                    else
                    {
                        pt[3] = "";
                    }
                    if (Directory.Exists(path + "\\Server\\Application\\Customization\\ReportObjects\\"))
                    {
                        pt[6] = "\\Server\\Application\\Customization\\ReportObjects\\";
                    }
                    else
                    {
                        pt[6] = "";
                    }
                    if (Directory.Exists(path + "\\WebServer\\bin\\Customization\\"))
                    {
                        pt[7] = "\\WebServer\\bin\\Customization\\";
                    }
                    else
                    {
                        pt[7] = "";
                    }
                    if (Directory.Exists(path + "\\Server\\Application\\Customization\\BusinessObjects\\DataModel\\"))
                    {
                        pt[9] = "\\Server\\Application\\Customization\\BusinessObjects\\DataModel\\";
                    }
                    else
                    {
                        pt[9] = "";
                    }
                }
            }
            else
            {
                pt[0] = "";
                pt[1] = "";
                pt[2] = "";
                pt[3] = "";
                pt[4] = "";
                pt[5] = "";
                pt[6] = "";
                pt[7] = "";
                pt[8] = "";
                pt[9] = "";
            }


            return pt;
        }

        private void comboBox2_Enter(object sender, EventArgs e)
        {
            LoadType();
            if (comboBox2.Text == "" && comboBox2.Items.Count > 0)
            {
                comboBox2.Text = comboBox2.Items[0].ToString();
            }
            if (comboBox2.Items.Count == 0)
            {
                comboBox2.Text = "";
            }
        }

        private void LoadType()
        {
            bool flag = false;
            DirectoryInfo dinfo = null;
            FileSystemInfo[] fsinfos = null;
            string[] pt = PanduanVersion(comboBox6.Text);
            comboBox2.Items.Clear();
            try
            {
                if (comboBox1.Text == "Designer Project")
                {
                    if (pt[1] == "")
                    {
                        //不做
                    }
                    else
                    {
                        dinfo = new DirectoryInfo(comboBox6.Text + pt[1] + "\\BusinessObjects\\");
                        dir = dinfo.FullName;
                        //获取指定目录下的所有子目录及文件类型
                        fsinfos = dinfo.GetFileSystemInfos();
                        foreach (FileSystemInfo fsinfo in fsinfos)
                        {

                            if (fsinfo is DirectoryInfo)    //判断是否文件夹
                            {
                                //使用获取的文件夹名称实例化DirectoryInfo对象
                                DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                                flag = false;
                                foreach (object list in comboBox2.Items)
                                {
                                    if (dirinfo.Name.Equals(list))
                                    {
                                        flag = true;
                                    }
                                }

                                if (!flag)
                                {
                                    //为ListView控件添加文件夹信息
                                    comboBox2.Items.Add(dirinfo.Name);
                                }
                            }
                        }
                    }

                    if (pt[3] == "")
                    {
                        //不做
                    }
                    else
                    {
                        if (Directory.Exists(comboBox6.Text + pt[3] + "\\BusinessObjects\\"))
                        {
                            dinfo = new DirectoryInfo(comboBox6.Text + pt[3] + "\\BusinessObjects\\");
                            dir = dinfo.FullName;
                            //获取指定目录下的所有子目录及文件类型
                            fsinfos = dinfo.GetFileSystemInfos();
                            foreach (FileSystemInfo fsinfo in fsinfos)
                            {
                                if (fsinfo is DirectoryInfo)    //判断是否文件夹
                                {
                                    //使用获取的文件夹名称实例化DirectoryInfo对象
                                    DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                                    flag = false;
                                    foreach (object list in comboBox2.Items)
                                    {
                                        if (dirinfo.Name.Equals(list))
                                        {
                                            flag = true;
                                        }
                                    }

                                    if (!flag)
                                    {
                                        //为ListView控件添加文件夹信息
                                        comboBox2.Items.Add(dirinfo.Name);
                                    }
                                }

                            }
                        }
                    }

                }

                if (comboBox1.Text == "Report Project")
                {
                    if (pt[4] == "")
                    {
                        //不做
                    }
                    else
                    {
                        dinfo = new DirectoryInfo(comboBox6.Text + pt[4]);
                        dir = dinfo.FullName;
                        //获取指定目录下的所有子目录及文件类型
                        fsinfos = dinfo.GetFileSystemInfos();
                        foreach (FileSystemInfo fsinfo in fsinfos)
                        {

                            if (fsinfo is DirectoryInfo)    //判断是否文件夹
                            {
                                //使用获取的文件夹名称实例化DirectoryInfo对象
                                DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                                flag = false;
                                foreach (object list in comboBox2.Items)
                                {
                                    if (dirinfo.Name.Equals(list))
                                    {
                                        flag = true;
                                    }
                                }

                                if (!flag)
                                {
                                    //为ListView控件添加文件夹信息
                                    comboBox2.Items.Add(dirinfo.Name);
                                }
                            }

                        }
                    }

                    if (pt[6] == "")
                    {
                        //不做
                    }
                    else
                    {
                        if (Directory.Exists(comboBox6.Text + pt[6]))
                        {
                            dinfo = new DirectoryInfo(comboBox6.Text + pt[6]);
                            dir = dinfo.FullName;
                            //获取指定目录下的所有子目录及文件类型
                            fsinfos = dinfo.GetFileSystemInfos();
                            foreach (FileSystemInfo fsinfo in fsinfos)
                            {
                                if (fsinfo is DirectoryInfo)    //判断是否文件夹
                                {
                                    //使用获取的文件夹名称实例化DirectoryInfo对象
                                    DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                                    flag = false;
                                    foreach (object list in comboBox2.Items)
                                    {
                                        if (dirinfo.Name.Equals(list))
                                        {
                                            flag = true;
                                        }
                                    }

                                    if (!flag)
                                    {
                                        //为ListView控件添加文件夹信息
                                        comboBox2.Items.Add(dirinfo.Name);
                                    }
                                }

                            }
                        }
                    }
                }
                if (comboBox1.Text == "Batch Project")
                {
                    if (pt[1] == "")
                    {
                        //不做
                    }
                    else
                    {
                        dinfo = new DirectoryInfo(comboBox6.Text + pt[1] + "\\BatchObjects\\");
                        dir = dinfo.FullName;
                        //获取指定目录下的所有子目录及文件类型
                        fsinfos = dinfo.GetFileSystemInfos();
                        foreach (FileSystemInfo fsinfo in fsinfos)
                        {

                            if (fsinfo is DirectoryInfo)    //判断是否文件夹
                            {
                                //使用获取的文件夹名称实例化DirectoryInfo对象
                                DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                                flag = false;
                                foreach (object list in comboBox2.Items)
                                {
                                    if (dirinfo.Name.Equals(list))
                                    {
                                        flag = true;
                                    }
                                }

                                if (!flag)
                                {
                                    //为ListView控件添加文件夹信息
                                    comboBox2.Items.Add(dirinfo.Name);
                                }
                            }

                        }
                    }
                    if (pt[3] == "")
                    {
                        //不做
                    }
                    else
                    {
                        if (Directory.Exists(comboBox6.Text + pt[3] + "\\BatchObjects\\"))
                        {
                            dinfo = new DirectoryInfo(comboBox6.Text + pt[3] + "\\BatchObjects\\");
                            dir = dinfo.FullName;
                            //获取指定目录下的所有子目录及文件类型
                            fsinfos = dinfo.GetFileSystemInfos();
                            foreach (FileSystemInfo fsinfo in fsinfos)
                            {
                                if (fsinfo is DirectoryInfo)    //判断是否文件夹
                                {
                                    //使用获取的文件夹名称实例化DirectoryInfo对象
                                    DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                                    flag = false;
                                    foreach (object list in comboBox2.Items)
                                    {
                                        if (dirinfo.Name.Equals(list))
                                        {
                                            flag = true;
                                        }
                                    }

                                    if (!flag)
                                    {
                                        //为ListView控件添加文件夹信息
                                        comboBox2.Items.Add(dirinfo.Name);
                                    }
                                }

                            }
                        }
                    }

                }
                if (comboBox1.Text == "DataModel Project")
                {
                    if (pt[8] == "")
                    {
                        //不做
                    }
                    else
                    {
                        dinfo = new DirectoryInfo(comboBox6.Text + pt[8]);
                        dir = dinfo.FullName;
                        //获取指定目录下的所有子目录及文件类型
                        fsinfos = dinfo.GetFileSystemInfos();
                        foreach (FileSystemInfo fsinfo in fsinfos)
                        {

                            if (!(fsinfo is DirectoryInfo))    //判断是否文件夹
                            {
                                //使用获取的文件夹名称实例化DirectoryInfo对象
                                FileInfo fileinfo = new FileInfo(fsinfo.Name);
                                flag = false;
                                foreach (object list in comboBox2.Items)
                                {
                                    if (fileinfo.Name.Equals(list))
                                    {
                                        flag = true;
                                    }
                                }

                                if (!flag)
                                {
                                    //为ListView控件添加文件夹信息
                                    comboBox2.Items.Add(fileinfo.Name);
                                }
                            }

                        }
                    }

                    if (pt[9] == "")
                    {
                        //不做
                    }
                    else
                    {
                        if (Directory.Exists(comboBox6.Text + pt[9]))
                        {
                            dinfo = new DirectoryInfo(comboBox6.Text + pt[9]);
                            dir = dinfo.FullName;
                            //获取指定目录下的所有子目录及文件类型
                            fsinfos = dinfo.GetFileSystemInfos();
                            foreach (FileSystemInfo fsinfo in fsinfos)
                            {
                                if (!(fsinfo is DirectoryInfo))    //判断是否文件夹
                                {
                                    //使用获取的文件夹名称实例化DirectoryInfo对象
                                    FileInfo fileinfo = new FileInfo(fsinfo.Name);
                                    flag = false;
                                    foreach (object list in comboBox2.Items)
                                    {
                                        if (fileinfo.Name.Equals(list))
                                        {
                                            flag = true;
                                        }
                                    }

                                    if (!flag)
                                    {
                                        //为ListView控件添加文件夹信息
                                        comboBox2.Items.Add(fileinfo.Name);
                                    }
                                }

                            }
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show("版本与本地平台路径不符，请确认！");
            }

            if (comboBox1.Text == "ValidatorSnippet Project")
            {
                return;
            }


        }

        private void PickType()
        {
            string[] pt = PanduanVersion(comboBox6.Text);
            string p_client = pt[1], p_server = pt[0], p_s_client = pt[3], p_s_server = pt[2], p_r_server = pt[4], p_r_client = pt[5], p_s_r_server = pt[6],
                    p_s_r_client = pt[7], p_DM = pt[8], p_s_DM = pt[9];

            Directory.CreateDirectory(textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text);
            Directory.CreateDirectory(textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[0] + "Programs\\");//server端DLL
            Directory.CreateDirectory(textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[1] + "Programs\\");//client端DLL
            if (pt[2] != "")
            {
                Directory.CreateDirectory(textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[2] + "Programs\\");//server二次开发DLL
            }
            if (pt[3] != "")
            {
                Directory.CreateDirectory(textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[3] + "Programs\\");//client二次开发DLL
            }
            if (pt[9] != "")
            {
                Directory.CreateDirectory(textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[9]);//DM二次开发
            }
            Directory.CreateDirectory(textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[8]);//DM

            //server端的Programs
            DirectoryInfo dinfo = new DirectoryInfo(comboBox6.Text + pt[0] + "\\Programs");
            FileSystemInfo[] fsinfos;
            if (Directory.Exists(dinfo.ToString()))
            {
                //获取指定目录下的所有子目录及文件类型
                fsinfos = dinfo.GetFileSystemInfos();

                foreach (FileSystemInfo fsinfo in fsinfos)
                {

                    if (fsinfo is DirectoryInfo)    //判断是否文件夹
                    {

                    }
                    else
                    {
                        string[] sp = fsinfo.Name.Split('.');
                        if (sp[0].Equals("Digiwin"))
                        {
                            if ((sp[2].Length == comboBox2.Text.Length) && fsinfo.Name.Substring(12, comboBox2.Text.Length).Equals(comboBox2.Text))
                            {
                                System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[0] + "\\Programs\\" + fsinfo.Name, true);
                            }

                        }
                    }

                }
            }

            //server二次开发的Programs
            dinfo = new DirectoryInfo(comboBox6.Text + pt[2] + "\\Programs");
            if (Directory.Exists(dinfo.ToString()))
            {
                //获取指定目录下的所有子目录及文件类型
                fsinfos = dinfo.GetFileSystemInfos();

                foreach (FileSystemInfo fsinfo in fsinfos)
                {

                    if (fsinfo is DirectoryInfo)    //判断是否文件夹
                    {

                    }
                    else
                    {
                        string[] sp = fsinfo.Name.Split('.');
                        if (sp[0].Equals("Digiwin"))
                        {
                            if (comboBox2.Text.StartsWith("X"))
                            {
                                if (sp[2].Equals(comboBox2.Text))
                                {
                                    System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[2] + "\\Programs\\" + fsinfo.Name, true);
                                }
                                if (sp[2].Equals("X_" + comboBox2.Text.Substring(1, comboBox2.Text.Length - 1)))
                                {
                                    System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[2] + "\\Programs\\" + fsinfo.Name, true);
                                }
                            }
                            else
                            {
                                if (sp[2].Equals("X" + comboBox2.Text))
                                {
                                    System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[2] + "\\Programs\\" + fsinfo.Name, true);
                                }
                                if (sp[2].Equals("X_" + comboBox2.Text))
                                {
                                    System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[2] + "\\Programs\\" + fsinfo.Name, true);
                                }
                            }
                        }
                    }

                }
            }

            //client端的Programs
            dinfo = new DirectoryInfo(comboBox6.Text + pt[1] + "\\Programs");
            if (Directory.Exists(dinfo.ToString()))
            {
                //获取指定目录下的所有子目录及文件类型
                fsinfos = dinfo.GetFileSystemInfos();
                foreach (FileSystemInfo fsinfo in fsinfos)
                {

                    if (fsinfo is DirectoryInfo)    //判断是否文件夹
                    {

                    }
                    else
                    {
                        string[] sp = fsinfo.Name.Split('.');
                        if (sp[0].Equals("Digiwin"))
                        {

                            if (fsinfo.Name.Substring(12, sp[2].Length).Equals(comboBox2.Text))//
                            {
                                System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[1] + "\\Programs\\" + fsinfo.Name, true);
                            }
                        }
                    }

                }
            }
            //client二次开发的Programs
            dinfo = new DirectoryInfo(comboBox6.Text + pt[3] + "\\Programs");
            if (Directory.Exists(dinfo.ToString()))
            {
                //获取指定目录下的所有子目录及文件类型
                fsinfos = dinfo.GetFileSystemInfos();
                foreach (FileSystemInfo fsinfo in fsinfos)
                {

                    if (fsinfo is DirectoryInfo)    //判断是否文件夹
                    {

                    }
                    else
                    {
                        string[] sp = fsinfo.Name.Split('.');
                        if (sp[0].Equals("Digiwin"))
                        {
                            if (comboBox2.Text.StartsWith("X"))
                            {
                                if (sp[2].Equals(comboBox2.Text))
                                {
                                    System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[3] + "\\Programs\\" + fsinfo.Name, true);
                                }
                                if (sp[2].Equals("X_" + comboBox2.Text.Substring(1, comboBox2.Text.Length - 1)))
                                {
                                    System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[3] + "\\Programs\\" + fsinfo.Name, true);
                                }
                            }
                            else
                            {
                                if (sp[2].Equals("X" + comboBox2.Text))
                                {
                                    System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[3] + "\\Programs\\" + fsinfo.Name, true);
                                }
                                if (sp[2].Equals("X_" + comboBox2.Text))
                                {
                                    System.IO.File.Copy(fsinfo.FullName, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[3] + "\\Programs\\" + fsinfo.Name, true);
                                }
                            }
                        }
                    }

                }
            }


            if (comboBox1.Text == "Designer Project")
            {
                if ((!comboBox2.Text.StartsWith("X")) && pt[0] != "")
                {
                    copyDirectory(comboBox6.Text + pt[0] + "BusinessObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[0] + "BusinessObjects\\" + comboBox2.Text);
                }
                if ((!comboBox2.Text.StartsWith("X")) && pt[1] != "")
                {
                    copyDirectory(comboBox6.Text + pt[1] + "BusinessObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[1] + "BusinessObjects\\" + comboBox2.Text);
                    copyDirectory(comboBox6.Text + pt[1] + "BusinessObjects\\ProgramInfoContainerElement", textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[1] + "BusinessObjects\\ProgramInfoContainerElement");
                }
                if (pt[2] != "" && Directory.Exists(comboBox6.Text + pt[2] + "BusinessObjects\\" + comboBox2.Text))
                {
                    copyDirectory(comboBox6.Text + pt[2] + "BusinessObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[2] + "BusinessObjects\\" + comboBox2.Text);
                }
                if (pt[3] != "" && Directory.Exists(comboBox6.Text + pt[3] + "BusinessObjects\\" + comboBox2.Text))
                {
                    copyDirectory(comboBox6.Text + pt[3] + "BusinessObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[3] + "BusinessObjects\\" + comboBox2.Text);
                    copyDirectory(comboBox6.Text + pt[3] + "BusinessObjects\\ProgramInfoContainerElement", textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[3] + "BusinessObjects\\ProgramInfoContainerElement");
                }
                MessageBox.Show("提取" + comboBox2.Text + "完成");
            }
            if (comboBox1.Text == "Report Project")
            {
                if ((!comboBox2.Text.StartsWith("X")) && pt[0] != "")
                {
                    copyDirectory(comboBox6.Text + pt[0] + "ReportObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[0] + "ReportObjects\\" + comboBox2.Text);

                }
                if ((!comboBox2.Text.StartsWith("X")) && pt[5] != "")
                {
                    copyDirectory(comboBox6.Text + pt[5] + "ReportObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[5] + "ReportObjects\\" + comboBox2.Text);

                }
                if (pt[2] != "" && Directory.Exists(comboBox6.Text + pt[2] + "ReportObjects\\" + comboBox2.Text))
                {
                    copyDirectory(comboBox6.Text + pt[2] + "ReportObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[2] + "ReportObjects\\" + comboBox2.Text);

                }
                if (pt[7] != "" && Directory.Exists(comboBox6.Text + pt[7] + "ReportObjects\\" + comboBox2.Text))
                {
                    copyDirectory(comboBox6.Text + pt[7] + "ReportObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[7] + "ReportObjects\\" + comboBox2.Text);

                }
                if ((!comboBox2.Text.StartsWith("X")) && pt[1] != "")
                {
                    copyDirectory(comboBox6.Text + pt[1] + "BusinessObjects\\ProgramInfoContainerElement", textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[1] + "BusinessObjects\\ProgramInfoContainerElement");

                }
                if (pt[3] != "" && Directory.Exists(comboBox6.Text + pt[3] + "BusinessObjects\\"))
                {
                    copyDirectory(comboBox6.Text + pt[3] + "BusinessObjects\\ProgramInfoContainerElement", textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[3] + "BusinessObjects\\ProgramInfoContainerElement");

                }

                MessageBox.Show("提取" + comboBox2.Text + "完成");
            }
            if (comboBox1.Text == "Batch Project")
            {
                if ((!comboBox2.Text.StartsWith("X")) && pt[0] != "")
                {
                    copyDirectory(comboBox6.Text + pt[0] + "BatchObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[0] + "BatchObjects\\" + comboBox2.Text);

                }
                if ((!comboBox2.Text.StartsWith("X")) && pt[1] != "")
                {
                    copyDirectory(comboBox6.Text + pt[1] + "BatchObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[1] + "BatchObjects\\" + comboBox2.Text);
                    copyDirectory(comboBox6.Text + pt[1] + "BusinessObjects\\ProgramInfoContainerElement", textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[1] + "BusinessObjects\\ProgramInfoContainerElement");

                }
                if (pt[2] != "" && Directory.Exists(comboBox6.Text + pt[2] + "BatchObjects\\" + comboBox2.Text))
                {
                    copyDirectory(comboBox6.Text + pt[2] + "BatchObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[2] + "BatchObjects\\" + comboBox2.Text);
                }
                if (pt[3] != "" && Directory.Exists(comboBox6.Text + pt[3] + "BatchObjects\\" + comboBox2.Text) && Directory.Exists(comboBox6.Text + pt[3] + "BusinessObjects\\"))
                {
                    copyDirectory(comboBox6.Text + pt[3] + "BatchObjects\\" + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[3] + "BatchObjects\\" + comboBox2.Text);
                    copyDirectory(comboBox6.Text + pt[3] + "BusinessObjects\\ProgramInfoContainerElement", textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[3] + "BusinessObjects\\ProgramInfoContainerElement");
                }
                MessageBox.Show("提取" + comboBox2.Text + "完成");
            }
            if (comboBox1.Text == "DataModel Project")
            {
                if ((!comboBox2.Text.StartsWith("X")) && pt[8] != "")
                {
                    System.IO.File.Copy(comboBox6.Text + pt[8] + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[8] + comboBox2.Text, true);
                }
                if (pt[9] != "" && Directory.Exists(comboBox6.Text + pt[9] + comboBox2.Text))
                {
                    System.IO.File.Copy(comboBox6.Text + pt[9] + comboBox2.Text, textBox6.Text + "\\平台文件\\" + comboBoxproduct2.Text + pt[9] + comboBox2.Text, true);
                }
                MessageBox.Show("提取" + comboBox2.Text + "完成");
            }
        }

        #endregion

        #region 菜单控制
        //菜单控制
        private void Invisible_Tab(object sender, EventArgs e)
        {
            this.tabControl1.TabPages.Remove(this.tabControl1.SelectedTab);

        }
        private void E10_Click(object sender, EventArgs e)
        {
            if (!this.tabControl1.TabPages.ContainsKey("tabPage1"))
            {
                this.tabControl1.TabPages.Add(this.tabPage1);
                this.tabControl1.SelectedTab = tabPage1;
            }
            this.tabControl1.SelectedTab = tabPage1;
        }
        private void CM_Click(object sender, EventArgs e)
        {
            if (!this.tabControl1.TabPages.ContainsKey("tabPage2"))
            {
                this.tabControl1.TabPages.Add(this.tabPage2);
                this.tabControl1.SelectedTab = tabPage2;
            }
            this.tabControl1.SelectedTab = tabPage2;
        }
        private void PL_BT_Click(object sender, EventArgs e)
        {
            if (!this.tabControl1.TabPages.ContainsKey("tabPage3"))
            {
                this.tabControl1.TabPages.Add(this.tabPage3);
                this.tabControl1.SelectedTab = tabPage3;
            }
            this.tabControl1.SelectedTab = tabPage3;
        }
        private void 基本设定_Click(object sender, EventArgs e)
        {
            if (!this.tabControl1.TabPages.ContainsKey("tabPage4"))
            {
                this.tabControl1.TabPages.Add(this.tabPage4);
                this.tabControl1.SelectedTab = tabPage4;
            }
            this.tabControl1.SelectedTab = tabPage4;
        }
        private void 数据库menuItem7_Click(object sender, EventArgs e)
        {
            if (!this.tabControl1.TabPages.ContainsKey("tabPage5"))
            {
                this.tabControl1.TabPages.Add(this.tabPage5);
                this.tabControl1.SelectedTab = tabPage5;
            }
            this.tabControl1.SelectedTab = tabPage5;
        }
        private void 服务器通讯_Click(object sender, EventArgs e)
        {
            if (!this.tabControl1.TabPages.ContainsKey("tabPage8"))
            {
                this.tabControl1.TabPages.Add(this.tabPage8);
                this.tabControl1.SelectedTab = tabPage8;
            }
            this.tabControl1.SelectedTab = tabPage8;
        }
        private void 退出_Click(object sender, EventArgs e)
        {
            if (client != null)
            {

                if (client.Client.Connected)
                {
                    AsyncSendMessage("Logout," + textBoxUserName.Text);
                    br.Close();
                    bw.Close();
                }
                isExit = true;
                client.Close();
            }

            Application.Exit();
        }
        private void 帮助_Click(object sender, EventArgs e)
        {
            Process.Start(System.Environment.CurrentDirectory + "\\help.chm");
        }
        private void DLL_Click(object sender, EventArgs e)
        {
            if (!this.tabControl1.TabPages.ContainsKey("tabPage10"))
            {
                this.tabControl1.TabPages.Add(this.tabPage10);
                this.tabControl1.SelectedTab = tabPage10;
            }
            this.tabControl1.SelectedTab = tabPage10;
        }
        private void 查询规格_Click(object sender, EventArgs e)
        {
            if (!this.tabControl1.TabPages.ContainsKey("tabPage11"))
            {
                this.tabControl1.TabPages.Add(this.tabPage11);
                this.tabControl1.SelectedTab = tabPage11;
            }
            this.tabControl1.SelectedTab = tabPage11;
        }
        private void KPI_Click(object sender, EventArgs e)
        {
            if (!this.tabControl1.TabPages.ContainsKey("tabPage9"))
            {
                this.tabControl1.TabPages.Add(this.tabPage9);
                this.tabControl1.SelectedTab = tabPage9;
            }
            this.tabControl1.SelectedTab = tabPage9;
        }
        private void 更新日志_Click(object sender, EventArgs e)
        {
            Form2 frm2 = new Form2();
            frm2.Show();
        }

        #endregion

        #region CM

        private void button46_Click(object sender, EventArgs e)
        {
            if (textBox4.Text == "")//判断是否输入数据库名称
            {
                MessageBox.Show("请输入要连接的数据库名称");//弹出提示信息
            }
            else
            {
                try//调用try…catch语句
                {
                    //声明一个字符串用于存储连接数据库字符串
                    string ConStr = "server=" + textBox7.Text + ";database=" + textBox4.Text.Trim() + ";uid=CM;pwd=111111";
                    //创建一个SqlConnection对象
                    conn = new SqlConnection(ConStr);
                    conn.Open();//打开连接
                    if (conn.State == ConnectionState.Open)//判断当前连接的状态
                    {
                        //显示状态信息
                        label3.Text = "数据库【" + textBox4.Text.Trim() + "】已经连接并打开";
                        timer1.Enabled = true;
                        SqlCommand cmd = new SqlCommand();	//创建一个SqlCommand对象
                        cmd.Connection = conn;				//设置Connection属性
                        //设置CommandText属性，设置SQL语句
                        cmd.CommandText = "select PRODUCT_GROUP_CODE FROM PRODUCT_GROUP WHERE ApproveStatus='Y' ORDER BY PRODUCT_GROUP_CODE";
                        //设置CommandType属性为Text，使其只执行SQL语句文本形式
                        cmd.CommandType = CommandType.Text;
                        SqlDataReader sdr = cmd.ExecuteReader();
                        while (sdr.Read())
                        {
                            WriteProduct(sdr["PRODUCT_GROUP_CODE"].ToString());
                        }
                        sdr.Close();
                        ReadProduct(comboBoxproduct);
                        //add 2014/01/06 FOR 增加组别的拉取↓
                        //comboBox5.Items.Clear();
                        cmd.CommandText = "SELECT ADMIN_UNIT_NAME FROM ADMIN_UNIT WHERE DEVELOP_DEPARTMENT='1' AND (END_DATE='9998-12-31 00:00:00.0000000' OR END_DATE>getdate()) order by ADMIN_UNIT_NAME";
                        cmd.CommandType = CommandType.Text;
                        sdr = cmd.ExecuteReader();
                        while (sdr.Read())
                        {
                            comboBox5.Items.Add(sdr["ADMIN_UNIT_NAME"].ToString());
                        }
                        sdr.Close();

                        //add 2014/01/06 FOR 增加组别的拉取↑
                        cmd.CommandText = "SELECT EMPLOYEE_NAME FROM dbo.EMPLOYEE WHERE ApproveStatus='Y'";
                        cmd.CommandType = CommandType.Text;
                        sdr = cmd.ExecuteReader();
                        while (sdr.Read())
                        {
                            //WritePerson(sdr["EMPLOYEE_NAME"].ToString());
                            comboBox8.Items.Add(sdr["EMPLOYEE_NAME"].ToString());
                        }
                        sdr.Close();
                        //ReadPerson(comboBox8);
                        //ReadPerson(comboBox9);
                    }
                }
                catch
                {
                    MessageBox.Show("连接数据库失败");//出现异常弹出提示
                }
            }
        }

        private void button47_Click(object sender, EventArgs e)
        {
            conn.Close();
            timer1.Enabled = false;
            label3.Text = "数据库【" + textBox4.Text.Trim() + "】已经断开";
        }

        private void button48_Click(object sender, EventArgs e)
        {
            try
            {
                //判断是否打开连接或者文本框不为空
                if (conn.State == ConnectionState.Open)
                {
                    SqlCommand cmd = new SqlCommand();	//创建一个SqlCommand对象
                    cmd.Connection = conn;				//设置Connection属性
                    //设置CommandText属性，设置SQL语句
                    cmd.CommandText = "select count(*) from ISSUE WHERE EMPLOYEE_ID in (select EMPLOYEE_ID from EMPLOYEE where EMPLOYEE_NAME='" + comboBox8.Text + "') and STATUS='0'";
                    //设置CommandType属性为Text，使其只执行SQL语句文本形式
                    cmd.CommandType = CommandType.Text;
                    //使用ExecuteScalar方法获取指定数据表中的数据数量
                    int i = Convert.ToInt32(cmd.ExecuteScalar());
                    textBox5.Text = i.ToString();
                    //MessageBox.Show("目前有" + textBox5.Text+"个新BUG！");
                }
                else
                {
                    button47_Click(sender, e);
                    button46_Click(sender, e);
                    button48_Click(sender, e);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("网络已断，请检查网络连接并重新连接！");
            }
        }

        private void btnTodayEvent_Click(object sender, EventArgs e)
        {
            try
            {
                //判断是否打开连接或者文本框不为空
                if (conn.State == ConnectionState.Open)
                {
                    SqlCommand cmd1 = new SqlCommand();	//创建一个SqlCommand对象
                    cmd1.Connection = conn;				//设置Connection属性
                    SqlCommand cmd2 = new SqlCommand();	//创建一个SqlCommand对象
                    cmd2.Connection = conn;				//设置Connection属性
                    cmd2.CommandText = "SELECT  COUNT(*) FROM    ( SELECT    A.DOC_NO FROM      dbo.ISSUE A LEFT JOIN dbo.ISSUE_D B ON A.ISSUE_ID = B.ISSUE_ID AND B.PROCESS_DATE BETWEEN CONVERT(VARCHAR(100), GETDATE(), 23) AND DATEADD(day, 1, CONVERT(VARCHAR(100), GETDATE(), 23)) INNER JOIN dbo.EMPLOYEE C ON A.EMPLOYEE_ID = C.EMPLOYEE_ID WHERE     A.STATUS IN ( '0', '3', '4' ) AND B.ISSUE_D_ID IS NULL AND A.DOC_NO LIKE '%B31%' AND C.EMPLOYEE_NAME = '" + comboBox8.Text + "' AND CONVERT(VARCHAR(100), A.CreateDate, 23) <> CONVERT(VARCHAR(100), GETDATE(), 23)) D";
                    cmd2.CommandType = CommandType.Text;
                    int i = Convert.ToInt32(cmd2.ExecuteScalar());
                    DateTime dt1 = DateTime.Parse("08:00:00");
                    DateTime dt2 = DateTime.Parse("19:00:00");
                    DateTime dt3 = DateTime.Parse(DateTime.Now.ToString("HH:mm:ss"));
                    cmd1.CommandText = "SELECT A.DOC_NO FROM ISSUE A INNER JOIN dbo.EMPLOYEE B ON A.EMPLOYEE_ID = B.EMPLOYEE_ID WHERE CONVERT(VARCHAR(100), A.PLAN_CLOSE_DATE, 23)=CONVERT(VARCHAR(100), GETDATE(), 23) AND A.STATUS IN ( '0', '3', '4' ) AND B.EMPLOYEE_NAME = '" + comboBox8.Text + "'";
                    cmd1.CommandType = CommandType.Text;
                    SqlDataReader sdr = cmd1.ExecuteReader();
                    string doc_NO = "";
                    while (sdr.Read())
                    {
                        doc_NO += sdr[0].ToString() + ";";
                    }
                    string jiean = "";
                    if (sdr.HasRows)
                    {
                        jiean = "     您今天需要结案的BUG单号为：" + doc_NO;
                    }
                    //cmd2.CommandText = "SELECT A.DOC_NO FROM ISSUE A INNER JOIN dbo.EMPLOYEE B ON A.EMPLOYEE_ID = B.EMPLOYEE_ID WHERE CONVERT(VARCHAR(100), A.PLAN_CLOSE_DATE, 23)=CONVERT(VARCHAR(100), GETDATE(), 23) AND A.STATUS IN ( '0', '3', '4' ) AND B.EMPLOYEE_NAME = '" + comboBox8.Text + "'";
                    //cmd2.CommandType = CommandType.Text;
                    //SqlDataReader sdr1 = cmd2.ExecuteReader();
                    if ((i > 0 && dt1 <= dt3 && dt3 <= dt2) || sdr.HasRows)
                    {
                        MessageBox.Show(" " + comboBox8.Text + " :" + "\r\n" + "     您今天有" + i + "个BUG单需回复，请尽快回复！" + "\r\n" + jiean, "今日事项");
                    }
                    sdr.Close();
                }
                else
                {
                    button47_Click(sender, e);
                    button46_Click(sender, e);
                    btnTodayEvent_Click(sender, e);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("网络已断，请检查网络连接并重新连接！");
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            button48_Click(sender, e);
            btnTodayEvent_Click(sender, e);
        }

        private void TextChange(object sender, EventArgs e)
        {

            if (textBox5.Text != "" && textBox5.Text != "0" && Convert.ToInt32(textBox5.Text) > RE_BUG)
            {
                this.TopMost = true;
                if (MessageBox.Show("你共有" + textBox5.Text + "未派工BUG！刚刚新来了" + (Convert.ToInt32(textBox5.Text) - RE_BUG) + "条BUG", "BUG", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    this.TopMost = false;
                }
                else
                {
                    this.TopMost = false;
                }
                RE_BUG = Convert.ToInt32(textBox5.Text);
            }
            if (Convert.ToInt32(textBox5.Text) < RE_BUG)
            {
                RE_BUG = Convert.ToInt32(textBox5.Text);
            }
        }
        //变化日期储存xml文件
        private void change_Date(object sender, EventArgs e)
        {
            //if (System.IO.File.Exists(str))											//判断是否存在INI文件
            //{
            //    WritePrivateProfileString(strOne, "Start_Date", dateTimePicker1.Value.ToString(), str); 		//修改INI文件中服务器节点的内容

            //}
            //else
            //{
            //    MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
            doc.Load("DefaultData.xml");
            XmlNode nd = doc.SelectSingleNode("//Start_Date");
            nd.InnerText = dateTimePicker1.Value.ToString();
            doc.Save("DefaultData.xml");
        }

        private void change_Com_Box8(object sender, EventArgs e)
        {
            //if (System.IO.File.Exists(str))											//判断是否存在INI文件
            //{
            //    WritePrivateProfileString(strOne, "person1", comboBox8.Text, str); 		//修改INI文件中服务器节点的内容

            //}
            //else
            //{
            //    MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
            doc.Load("DefaultData.xml");
            XmlNode nd = doc.SelectSingleNode("//Person1");
            nd.InnerText = comboBox8.Text;
            doc.Save("DefaultData.xml");
        }

        private void change_Group(object sender, EventArgs e)
        {
            //if (System.IO.File.Exists(str))											//判断是否存在INI文件
            //{
            //    WritePrivateProfileString(strOne, "group", comboBox5.Text, str); 		//修改INI文件中服务器节点的内容

            //}
            //else
            //{
            //    MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
            doc.Load("DefaultData.xml");
            XmlNode nd = doc.SelectSingleNode("//Group");
            nd.InnerText = comboBox5.Text;
            doc.Save("DefaultData.xml");

            string sql = "SELECT EMPLOYEE_NAME FROM dbo.EMPLOYEE LEFT JOIN dbo.EMPLOYEE_D ON dbo.EMPLOYEE.EMPLOYEE_ID = dbo.EMPLOYEE_D.EMPLOYEE_ID LEFT JOIN dbo.ADMIN_UNIT ON dbo.EMPLOYEE_D.ADMIN_UNIT_ID = dbo.ADMIN_UNIT.ADMIN_UNIT_ID WHERE EMPLOYEE.ApproveStatus='Y' AND ADMIN_UNIT_NAME='" + comboBox5.Text + "'";
            SqlCommand cmd = new SqlCommand(sql, conn);
            //string str = Convert.ToString(cmd.ExecuteScalar());

            //SqlCommand cmd1 = new SqlCommand();	//创建一个SqlCommand对象
            //cmd1.Connection = conn;
            //cmd1.CommandText = "SELECT EMPLOYEE_NAME FROM dbo.EMPLOYEE LEFT JOIN dbo.EMPLOYEE_D ON dbo.EMPLOYEE.EMPLOYEE_ID = dbo.EMPLOYEE_D.EMPLOYEE_ID LEFT JOIN dbo.ADMIN_UNIT ON dbo.EMPLOYEE_D.ADMIN_UNIT_ID = dbo.ADMIN_UNIT.ADMIN_UNIT_ID WHERE EMPLOYEE.ApproveStatus='Y' AND ADMIN_UNIT_NAME='"+comboBox5.Text+"'";
            //cmd1.CommandType = CommandType.Text;
            SqlDataReader sdr = cmd.ExecuteReader();
            comboBox9.Items.Clear();
            comboBox9.Items.Add("全部");
            bool bol = true;
            while (sdr.Read())
            {
                comboBox9.Items.Add(sdr["EMPLOYEE_NAME"].ToString());
                if (sdr["EMPLOYEE_NAME"].ToString().Equals(comboBox9.Text))
                {
                    bol = false;
                }
            }

            if (bol)
            {
                comboBox9.Text = "全部";
            }
            sdr.Close();
        }

        private void change_Com_Box9(object sender, EventArgs e)
        {
            //if (System.IO.File.Exists(str))											//判断是否存在INI文件
            //{
            //    WritePrivateProfileString(strOne, "person2", comboBox9.Text, str); 		//修改INI文件中服务器节点的内容

            //}
            //else
            //{
            //    MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
            doc.Load("DefaultData.xml");
            XmlNode nd = doc.SelectSingleNode("//Person2");
            nd.InnerText = comboBox9.Text;
            doc.Save("DefaultData.xml");
        }

        //private void change_Com_Box4(object sender, EventArgs e)
        //{

        //    //if (System.IO.File.Exists(str))											//判断是否存在INI文件
        //    //{
        //    //    WritePrivateProfileString(strOne, "bug_Status", comboBox4.Text, str); 		//修改INI文件中服务器节点的内容

        //    //}
        //    //else
        //    //{
        //    //    MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
        //    //}
        //    doc.Load("DefaultData.xml");
        //    XmlNode nd = doc.SelectSingleNode("//Bug_Status");
        //    nd.InnerText = comboBox4.Text;
        //    doc.Save("DefaultData.xml");
        //}

        private void change_Com_Box7(object sender, EventArgs e)
        {

            //if (System.IO.File.Exists(str))											//判断是否存在INI文件
            //{
            //    WritePrivateProfileString(strOne, "bug_Type", comboBox7.Text, str); 		//修改INI文件中服务器节点的内容

            //}
            //else
            //{
            //    MessageBox.Show("对不起，你所要修改的文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
            doc.Load("DefaultData.xml");
            XmlNode nd = doc.SelectSingleNode("//Bug_Type");
            nd.InnerText = comboBox7.Text;
            doc.Save("DefaultData.xml");
        }

        private void button50_Click(object sender, EventArgs e)
        {
            try
            {
                string Bug;
                string bugStutas;
                string person;
                string unit;
                string type;
                if (comboBox12.Text == "异常单")
                {
                    type = "1";
                }
                else
                {
                    type = "2";
                }

                if (comboBox7.Text == "未结")
                {
                    bugStutas = "CAST(ISSUE.CLOSED_DATE AS DATE) = '1900-01-01'";
                }
                else if (comboBox7.Text == "已结")
                {
                    bugStutas = "CAST(ISSUE.CLOSED_DATE AS DATE) != '1900-01-01'";
                }
                else
                {
                    bugStutas = "1=1";
                }

                if (comboBox9.Text == "全部")
                {
                    person = "1=1";
                }
                else
                {
                    person = "E1.EMPLOYEE_NAME='" + comboBox9.Text + "'";
                }

                if (comboBox5.Text == "全部")
                {
                    unit = "1=1";
                }
                else
                {
                    unit = "ADMIN_UNIT.ADMIN_UNIT_NAME ='" + comboBox5.Text + "'";

                }
                string sql = "select WCG.* ";
                //sql += " ( DateDiff ( day, WCG.创建日期 , WCG.结案日期 ) - DateDiff( week , WCG.创建日期 , WCG.结案日期 ) * 2 + case   when   datepart(dw, WCG.创建日期)   between   2   and   7   then   1   else   0   end ";
                //sql += " - case   when   datepart(dw, WCG.结案日期) = 7   then   1   else   0   end ";
                //sql += " + case   when   DATEPART(DW,WCG.创建日期) in (7,1) and DATEPART(DW,WCG.结案日期) in (7,1) then 1 else 0 end ) as 所用天数 ";
                //sql += "WCG.CLOSED_DAYS as 所用天数 ";
                sql += "from (SELECT ADMIN_UNIT_NAME AS '部门',E1.EMPLOYEE_NAME 处理人,E2.EMPLOYEE_NAME 反映人,ISSUE.DOC_NO 单号,ISSUE.CUSTOMER_NAME 客户简称,CAST(ISSUE.CreateDate AS date) 创建日期,case when CAST(ISSUE.CLOSED_DATE AS date) ='1900-01-01' then '' else CAST(ISSUE.CLOSED_DATE AS VARCHAR(10)) end 结案日期,case when CAST(ISSUE.CLOSED_DATE AS date) ='1900-01-01' then '未结' else '已结' end 是否结案,CASE WHEN ISSUE.CATEGORY = '1' THEN (CASE WHEN RESPONSE_TYPE = '1' THEN '外部Bug' ELSE '内部Bug' END) ELSE '建议单' END 反应类型,MODULE.MODULE_NAME 模块,CI.CI_NAME 程序名称,right(E3.EMPLOYEE_NAME,2) SA姓名,E3.EMAIL 邮箱地址,J.CLOSED_DAYS AS 结案天数,ISSUE.ISSUE_DESCRIPTION 问题描述,dbo.ISSUE.REPLY_DESCRIPTION AS 处理回复 FROM ISSUE LEFT JOIN (SELECT ISSUE_ID,MAX(CLOSED_DAYS) AS CLOSED_DAYS FROM dbo.ISSUE_D2 GROUP BY ISSUE_ID) AS J ON ISSUE.ISSUE_ID=J.ISSUE_ID LEFT JOIN EMPLOYEE E1 ON ISSUE.EMPLOYEE_ID=E1.EMPLOYEE_ID LEFT JOIN EMPLOYEE_D ON E1.EMPLOYEE_ID=EMPLOYEE_D.EMPLOYEE_ID LEFT JOIN ADMIN_UNIT ON ADMIN_UNIT.ADMIN_UNIT_ID=EMPLOYEE_D.ADMIN_UNIT_ID left Join MODULE on ISSUE.MODULE_ID=MODULE.MODULE_ID LEFT JOIN dbo.MODULE_D ON dbo.MODULE.MODULE_ID=dbo.MODULE_D.MODULE_ID AND MODULE_D.DOC_ID='2E250852-2B0A-4121-B3CA-5C99CE5AE1FF' LEFT JOIN dbo.EMPLOYEE E3 ON dbo.MODULE_D.EMPLOYEE_ID = E3.EMPLOYEE_ID LEFT JOIN dbo.CI ON dbo.ISSUE.CI_ID=CI.CI_ID left join EMPLOYEE E2 on ISSUE.RESPONSE_BY=E2.EMPLOYEE_ID WHERE RESPONSE_TYPE = '1' AND EMPLOYEE_D.IS_PRIMARY = 1 AND ISSUE.CATEGORY='" + type + "'AND " + bugStutas + " AND " + person + " and " + unit + ") AS WCG ";
                //sql += "left Join ISSUE ";
                //sql += "on WCG.BUG单号=ISSUE.DOC_NO ";
                sql += "where (CAST(WCG.结案日期 AS date)>='" + dateTimePicker1.Value.ToShortDateString() + "' ";
                sql += "and CAST(WCG.结案日期 AS date)<='" + dateTimePicker2.Value.ToShortDateString() + "') ";
                sql += "or CAST(WCG.结案日期 AS date) ='1900-01-01' ";
                string sql0 = "select count(*) from (" + sql + ") as JS";
                string sql1 = "select count(*) from (" + sql + ") as JS where JS.结案日期 !='' ";
                string sql2 = "select count(*) from (" + sql + ") as JS where JS.结案天数 <=3 and JS.结案日期 !=''";
                string sql3 = "select count(*) from (" + sql + ") as JS where JS.结案天数 >3 ";

                //创建一个SqlCommand对象
                SqlCommand cmd = new SqlCommand(sql0, conn);
                int i = Convert.ToInt32(cmd.ExecuteScalar());
                textBox1.Text = i.ToString();

                cmd = new SqlCommand(sql1, conn);
                int i2 = Convert.ToInt32(cmd.ExecuteScalar());
                textBox10.Text = i2.ToString();

                cmd = new SqlCommand(sql2, conn);
                decimal i3 = Convert.ToInt32(cmd.ExecuteScalar());

                cmd = new SqlCommand(sql3, conn);
                decimal i4 = Convert.ToInt32(cmd.ExecuteScalar());

                if (i == 0 || i2 == 0)
                {
                    textBox8.Text = "0%";
                    textBox8.BackColor = Color.White;
                    textBox9.Text = "0%";
                }
                else if (i3 == 0 && i4 != 0)
                {
                    textBox8.Text = "0%";
                    textBox8.BackColor = Color.Red;
                    textBox9.Text = "100%";
                }
                else if (i4 == 0 && i3 != 0)
                {
                    textBox8.Text = "100%";
                    textBox8.BackColor = Color.Green;
                    textBox9.Text = "0%";
                }
                else
                {
                    //textBox8.Text = (i3).ToString();
                    //textBox9.Text = (i4).ToString();
                    textBox8.Text = Convert.ToString(Math.Round((i3 / i2) * 100, 2)) + "%";
                    textBox9.Text = Convert.ToString(Math.Round((i4 / i2) * 100, 2)) + "%";

                    if (((i3 / i2) * 100) < Convert.ToInt16(textBox33.Text))
                    {
                        textBox8.BackColor = Color.Red;
                    }
                    else
                    {
                        textBox8.BackColor = Color.Green;
                    }
                }


                SqlDataAdapter sda = new SqlDataAdapter(sql, conn);//创建一个SqlDataAdapter对象
                // sda.SelectCommand = cmd;				//设置SqlDataAdapter对象的SelectCommand属性为cmd
                DataSet ds = new DataSet();				//创建一个DataSet对象
                sda.Fill(ds);				//使用SqlDataAdapter对象的Fill方法填充DataSet数据集;
                dataGridView1.DataSource = ds.Tables[0];//设置dataGridView1控件的数据源
            }
            catch (Exception ex)
            {
                MessageBox.Show("网络已断，请检查网络连接并重新连接！");
            }

        }

        private Excel.Application G_ea;//定义Word应用程序字段
        private object G_missing = //定义G_missing字段并添加引用
            System.Reflection.Missing.Value;

        private void button51_Click(object sender, EventArgs e)
        {
            List<Bug> P_Fruit = new List<Bug>();//创建数据集合
            foreach (DataGridViewRow dgvr in dataGridView1.Rows)
            {
                if (dgvr.Cells[0].Value == null)
                {
                    continue;
                }
                P_Fruit.Add(new Bug()//向数据集合添加数据
                {
                    Dep = dgvr.Cells[0].Value.ToString(),
                    Name = dgvr.Cells[1].Value.ToString(),
                    Doc_No = dgvr.Cells[2].Value.ToString(),
                    Date_Create = dgvr.Cells[3].Value.ToString(),
                    Date_Over = dgvr.Cells[4].Value.ToString(),
                    Is = dgvr.Cells[5].Value.ToString(),
                    Type = dgvr.Cells[6].Value.ToString(),
                    Model = dgvr.Cells[7].Value.ToString(),
                    Cla = dgvr.Cells[8].Value.ToString()

                });
            }
            SaveFileDialog P_SaveFileDialog =//创建保存文件对话框对象
                new SaveFileDialog();
            P_SaveFileDialog.Filter = "*.xls|*.xlsx";
            if (DialogResult.OK ==//确认是否保存文件
                P_SaveFileDialog.ShowDialog())
            {
                ThreadPool.QueueUserWorkItem(//开始线程池
                (pp) =>//使用lambda表达式
                {
                    G_ea = new Microsoft.Office.Interop.Excel.Application();//创建应用程序对象
                    Excel.Workbook P_wk = G_ea.Workbooks.Add(G_missing);//创建Excel文档
                    Excel.Worksheet P_ws = (Excel.Worksheet)P_wk.Worksheets.Add(//创建工作区域
                        G_missing, G_missing, G_missing, G_missing);
                    for (int i = 0; i < P_Fruit.Count; i++)
                    {
                        P_ws.Cells[i + 1, 1] = P_Fruit[i].Dep;//向Excel文档中写入内容
                        P_ws.Cells[i + 1, 2] = P_Fruit[i].Name;//向Excel文档中写入内容
                        P_ws.Cells[i + 1, 3] = P_Fruit[i].Doc_No;//向Excel文档中写入内容
                        P_ws.Cells[i + 1, 4] = P_Fruit[i].Date_Create;//向Excel文档中写入内容
                        P_ws.Cells[i + 1, 5] = P_Fruit[i].Date_Over;//向Excel文档中写入内容
                        P_ws.Cells[i + 1, 6] = P_Fruit[i].Is;//向Excel文档中写入内容
                        P_ws.Cells[i + 1, 7] = P_Fruit[i].Type;//向Excel文档中写入内容
                        P_ws.Cells[i + 1, 8] = P_Fruit[i].Model;//向Excel文档中写入内容
                        P_ws.Cells[i + 1, 9] = P_Fruit[i].Cla;//向Excel文档中写入内容
                    }
                    P_wk.SaveAs(//保存Word文件
                        P_SaveFileDialog.FileName, G_missing, G_missing, G_missing,
                        G_missing, G_missing, Excel.XlSaveAsAccessMode.xlShared, G_missing,
                        G_missing, G_missing, G_missing, G_missing);
                    ((Excel._Application)G_ea.Application).Quit();//退出应用程序

                    this.Invoke(//调用窗体线程
                        (MethodInvoker)(() =>//使用lambda表达式
                        {
                            MessageBox.Show(//弹出消息对话框
                                "成功创建Excel文档！", "提示！");
                        }));
                });
            }
        }

        #endregion

        #region PickList&BusinessType

        private void Dir1_Load(object sender, EventArgs e)
        {
            comboBox3.Text = "";
            comboBox3.Items.Clear();
            richTextBox1.Clear();
            DirectoryInfo dinfo = null;
            if (!Directory.Exists(comboBox6.Text + "\\Server\\Application\\BusinessObjects\\MetadataContainerElement"))
            {
                if (!Directory.Exists(comboBox6.Text + "\\BusinessObjects\\MetadataContainerElement"))
                {
                    if (!Directory.Exists(comboBox6.Text + "\\Server\\BusinessObjects\\MetadataContainerElement"))
                    {
                        return;
                    }
                    else
                    {
                        dinfo = new DirectoryInfo(comboBox6.Text + "\\Server\\BusinessObjects\\MetadataContainerElement");
                    }
                }
                else
                {
                    dinfo = new DirectoryInfo(comboBox6.Text + "\\BusinessObjects\\MetadataContainerElement");
                }
            }
            else
            {
                dinfo = new DirectoryInfo(comboBox6.Text + "\\Server\\Application\\BusinessObjects\\MetadataContainerElement");
            }

            //获取指定目录下的所有子目录及文件类型
            FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
            foreach (FileSystemInfo fsinfo in fsinfos)
            {
                if (fsinfo is DirectoryInfo)    //判断是否文件夹
                {
                    //使用获取的文件夹名称实例化DirectoryInfo对象
                    //DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName);
                    //为ListView控件添加文件夹信息
                    //comboBox2.Items.Add(dirinfo.Name);

                }
                else
                {
                    //使用获取的文件夹名称实例化FileInfo对象
                    FileInfo dirinfo = new FileInfo(fsinfo.FullName);
                    //为ListView控件添加文夹信息
                    if (radioButton1.Checked)
                    {
                        if (dirinfo.Name.Substring(0, 12) == "PickListType")
                        {
                            comboBox3.Items.Add(dirinfo.Name.Substring(13));
                        }

                    }
                    else
                    {
                        if (dirinfo.Name.Substring(0, 12) == "BusinessType")
                        {
                            comboBox3.Items.Add(dirinfo.Name.Substring(13));
                        }

                    }

                }

            }
            if (comboBox3.Items.Count > 0)
            {
                comboBox3.Text = comboBox3.Items[0].ToString();
            }

        }
        private void displayText(object sender, EventArgs e)
        {
            if (comboBox3.Text == "")
            {
                richTextBox1.Clear();
                return;
            }
            richTextBox1.Clear();
            string mulu;
            if (!Directory.Exists(comboBox6.Text + "\\Server\\Application\\BusinessObjects\\MetadataContainerElement"))
            {
                if (!Directory.Exists(comboBox6.Text + "\\BusinessObjects\\MetadataContainerElement"))
                {
                    if (!Directory.Exists(comboBox6.Text + "\\Server\\BusinessObjects\\MetadataContainerElement"))
                    {
                        return;
                    }
                    else
                    {
                        mulu = comboBox6.Text + "\\Server\\BusinessObjects\\MetadataContainerElement";
                    }
                }
                else
                {
                    mulu = comboBox6.Text + "\\BusinessObjects\\MetadataContainerElement";
                }
            }
            else
            {
                mulu = comboBox6.Text + "\\Server\\Application\\BusinessObjects\\MetadataContainerElement";
            }
            StreamReader SReader = null;
            if (radioButton1.Checked)
            {

                SReader = new StreamReader(mulu + "\\PickListType." + comboBox3.Text, Encoding.UTF8);
            }
            else
            {

                SReader = new StreamReader(mulu + "\\BusinessType." + comboBox3.Text, Encoding.UTF8);
            }
            string strLine = string.Empty;
            while ((strLine = SReader.ReadLine()) != null)
            {
                richTextBox1.Text += strLine + Environment.NewLine;
            }
        }

        #endregion

        #region 递归拷贝所有子目录方法

        /// <summary>
        /// 递归拷贝所有子目录。
        /// </summary>
        /// <param >源目录</param>
        /// <param >目的目录</param>
        private void copyDirectory(string sPath, string dPath)
        {
            //try
            //{
            string[] directories = System.IO.Directory.GetDirectories(sPath);
            if (!System.IO.Directory.Exists(dPath))
                System.IO.Directory.CreateDirectory(dPath);
            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(sPath);
            System.IO.DirectoryInfo[] dirs = dir.GetDirectories();
            CopyAllFile(dir, dPath);
            if (dirs.Length > 0)
            {
                foreach (System.IO.DirectoryInfo temDirectoryInfo in dirs)
                {
                    string sourceDirectoryFullName = temDirectoryInfo.FullName;
                    string destDirectoryFullName = sourceDirectoryFullName.Replace(sPath, dPath);
                    if (!System.IO.Directory.Exists(destDirectoryFullName))
                    {
                        System.IO.Directory.CreateDirectory(destDirectoryFullName);
                    }
                    CopyAllFile(temDirectoryInfo, destDirectoryFullName);
                    copyDirectory(sourceDirectoryFullName, destDirectoryFullName);
                }
            }
            //}
            //catch
            //{
            //    MessageBox.Show(sPath + "文件夹不存在！记得检查版本哦！");
            //}
        }

        /// <summary>
        /// 拷贝目录下的所有文件到目的目录。
        /// </summary>
        /// <param >源路径</param>
        /// <param >目的路径</param>
        private void CopyAllFile(System.IO.DirectoryInfo path, string desPath)
        {
            string sourcePath = path.FullName;
            System.IO.FileInfo[] files = path.GetFiles();
            foreach (System.IO.FileInfo file in files)
            {
                string sourceFileFullName = file.FullName;
                string destFileFullName = sourceFileFullName.Replace(sourcePath, desPath);
                if (file.Attributes.ToString().IndexOf("ReadOnly") != -1)
                {
                    file.Attributes = FileAttributes.Normal;
                }
                file.CopyTo(destFileFullName, true);
            }
        }

        #endregion

        #region 备份平台文件
        private void comboBoxproduct12_SelectedIndexChanged(object sender, EventArgs e)
        {
            Dir_Load(comboBoxproduct12, comboBox13, comboBox14);
            dir_bak = dir;
        }

        private void comboBox13_SelectedIndexChanged(object sender, EventArgs e)
        {
            Dir_Load(comboBoxproduct12, comboBox13, comboBox14);
            dir_bak = dir;
        }

        private void button44_Click(object sender, EventArgs e) //打开备份文件夹
        {
            string Tempdir = "";
            Tempdir = "\\" + comboBoxproduct12.Text;
            if (Directory.Exists(textBox19.Text + Tempdir + "\\" + comboBox14.Text))
            {
                Process.Start(textBox19.Text + Tempdir + "\\" + comboBox14.Text);
            }

        }

        private void button45_Click(object sender, EventArgs e) //备份设计器文件
        {

            string Tempdir = "";
            Tempdir = "\\" + comboBoxproduct12.Text;
            copyDirectory(dir_bak + comboBox14.Text, textBox19.Text + Tempdir + "\\" + comboBox14.Text + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "—" + DateTime.Now.ToString("HH-mm-ss") + "—" + textBox29.Text);
            MessageBox.Show("备份" + comboBox14.Text + "成功");
        }

        #endregion

        #region 基本设定

        //提取文件路径设定按钮
        private void button61_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox6.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox6.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button63_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox11.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox11.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button64_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox12.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox12.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button65_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox13.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox13.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button66_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox14.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox14.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button68_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox15.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox15.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button67_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox16.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox16.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button69_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox17.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox17.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button70_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox18.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox18.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button71_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox19.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox19.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button72_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox20.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox20.Text = folderBrowserDialog1.SelectedPath;
            }

        }

        private void button73_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox21.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox21.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button74_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox22.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox22.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button75_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox23.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox23.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button76_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox24.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox24.Text = folderBrowserDialog1.SelectedPath;
            }

        }

        private void button77_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox25.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox25.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button35_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox44.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox44.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button36_Click_1(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBox45.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox45.Text = folderBrowserDialog1.SelectedPath;
            }
        }
        /// <summary>
        /// LOAD基本设定文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button79_Click(object sender, EventArgs e)
        {
            //WritePrivateProfileString(strOne, "directory_File", textBox6.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "CMIP", textBox7.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "directory_File1", textBox11.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "directory_File2", textBox12.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "directory_File3", textBox13.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "directory_File4", textBox14.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "directory_File5", textBox15.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "directory_File6", textBox16.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "directory_File7", textBox17.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "directory_File8", textBox18.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "directory_File9", textBox19.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "directory_File10", textBox20.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "directory_File11", textBox21.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "directory_File12", textBox22.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "Driver", textBox23.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "directory_File14", textBox24.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "directory_File15", textBox25.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "ServerIP", textBox30.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "ServerPort", textBox31.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "CM_PWD", textBox32.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "111_PWD", textBox34.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "11_PWD", textBox35.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "HJDZ_PWD", textBox36.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "ALEX_PWD", textBox37.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "SEC", textBox33.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "Site", textBox38.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "Programm", textBox39.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "SPEC", textBox44.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "SRC", textBox45.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "BUG_TIME", textBox46.Text, str); 		//修改INI文件中服务器节点的内容
            //WritePrivateProfileString(strOne, "SPEC_ADD", textBox47.Text, str); 		//修改INI文件中服务器节点的内容
            doc.Load("DefaultData.xml");
            XmlNode root = doc.SelectSingleNode("DataBase");
            XmlNodeList childlist = root.ChildNodes;
            childlist[1].InnerText = textBox7.Text;
            childlist[3].InnerText = comboBox8.Text;
            childlist[6].InnerText = textBox6.Text;
            childlist[7].InnerText = textBox19.Text;
            childlist[8].InnerText = textBox25.Text;
            childlist[9].InnerText = toolStripTextBox3.Text;
            childlist[10].InnerText = textBox30.Text;
            childlist[11].InnerText = textBox31.Text;
            childlist[14].InnerText = textBox38.Text;
            childlist[15].InnerText = textBox39.Text;
            childlist[17].InnerText = textBox46.Text;
            childlist[18].InnerText = textBox47.Text;
            childlist[23].InnerText = textBox23.Text;
            childlist[27].InnerText = textBox4.Text;
            childlist[28].InnerText = textBox33.Text;
            childlist[30].InnerText = textBox48.Text;
            childlist[31].InnerText = textBox49.Text;
            childlist[32].InnerText = textBox50.Text;
            childlist[33].InnerText = textBox51.Text;
            childlist[34].InnerText = textBox52.Text;
            childlist[35].InnerText = textBox53.Text;
            //if (textBox33.Text != "")
            //{
            //    _SEC = Convert.ToInt32(textBox33.Text) * 1000;
            //}
            if (textBox46.Text != "")
            {
                timer1.Interval = (int)(Convert.ToDecimal(textBox46.Text) * 60 * 1000);
            }
            doc.Save("DefaultData.xml");
            MessageBox.Show("保存成功！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //if (textBox33.Text != "")
            //{
            //    _SEC = Convert.ToInt32(textBox33.Text) * 1000;
            //}
        }

        private void WritePerson(string S)
        {
            bool flag = false;
            foreach (object list in comboBox8.Items)
            {
                if (S.Equals(list))
                {
                    flag = true;
                }
            }

            if (!flag)
            {
                var Current = Directory.GetCurrentDirectory();//获取当前根目录
                //true是追加方式，false是覆盖方式
                StreamWriter w = new StreamWriter(Current + "\\person.txt", true);
                w.WriteLine(S, Encoding.UTF8);
                w.Flush();
                w.Close();
            }
        }

        private void ReadPerson(ComboBox combox)
        {
            var Current = Directory.GetCurrentDirectory();//获取当前根目录
            //true是追加方式，false是覆盖方式
            StreamReader w = new StreamReader(Current + "\\person.txt", true);
            string strLine = string.Empty;
            while ((strLine = w.ReadLine()) != null)
            {
                bool flag = false;
                foreach (object list in combox.Items)
                {
                    if (strLine.Equals(list))
                    {
                        flag = true;
                    }
                }

                if (!flag)
                {
                    combox.Items.Add(strLine);
                }
            }
            w.Close();
        }

        #endregion

        #region 单只编译查询、提取

        private void comboBoxproduct1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Dir_Load(comboBoxproduct1, comboBox1, comboBox2);
            //dir_pick = dir;
            comboBox10.Items.Clear();
            //Dir2_Load();
        }
        //单只编译查询、提取

        //String r = "";
        //private void panduan(object sender, EventArgs e)
        //{

        //    if (r == comboBoxproduct1.Text)
        //    {
        //        return;
        //    }
        //    else
        //    {
        //        Dir2_Load();
        //        r = comboBoxproduct1.Text;
        //    }
        //}
        private void Dir2_Load()
        {
            DirectoryInfo dinfo = null;

            if (check_bak.Checked)
            {
                dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp_BAK\" + comboBoxproduct1.Text);
            }
            else
            {
                dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp\" + comboBoxproduct1.Text);
            }

            //获取指定目录下的所有子目录及文件类型
            FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
            comboBox10.Items.Clear();
            foreach (FileSystemInfo fsinfo in fsinfos)
            {
                comboBox10.Items.Add(fsinfo.Name);
            }
        }

        /// <summary>
        /// 一键提取
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button60_Click(object sender, EventArgs e)
        {
            string sql = "     SELECT DISTINCT ";
            sql += "             [A].[DOC_NO], ";
            sql += "             [D].[CI_NAME], ";
            sql += "            [A].[FIRST_SUBMIT_DATE] ";
            sql += "     FROM    [APPLY_CI] AS [A] ";
            sql += "LEFT OUTER JOIN [PRODUCT_GROUP] AS [C] ON [C].[PRODUCT_GROUP_ID] = [A].[PRODUCT_GROUP_ID] ";
            sql += "LEFT OUTER JOIN [CI] AS [D] ON [D].[CI_ID] = [A].[CI_ID] ";
            sql += "INNER JOIN [APPLY_CI_D1] AS [G] ON [G].[APPLY_CI_ID] = [A].[APPLY_CI_ID] ";
            sql += "LEFT OUTER JOIN [EMPLOYEE] AS [E] ON [E].[EMPLOYEE_ID] = [A].[APPLY_BY] ";
            sql += "LEFT OUTER JOIN [EMPLOYEE] AS [F] ON [F].[EMPLOYEE_ID] = [G].[PROCESS_BY] ";
            sql += "WHERE   [A].[CATEGORY] IN ( '3', '5' ) ";
            sql += "AND [A].[STATUS] <> '3' ";
            sql += "AND [A].[STATUS] <> '4' ";
            sql += "AND [A].[STATUS] <> '1' ";
            sql += "AND [G].[CLOSE_DATE] = '1900-01-01 00:00:00.0000000' ";
            //sql +=            "AND E.EMPLOYEE_NAME <> '"+comboBox8.Text+"' ";
            sql += "AND [F].[EMPLOYEE_NAME] = '" + comboBox8.Text + "' ";
            sql += "AND [C].[PRODUCT_GROUP_CODE] = '" + comboBoxproduct1.Text + "'";
            sql += "AND ( G.WORK_ITEM_NAME = '6' ";
            sql += "       OR G.WORK_ITEM_NAME = '7') ";
            sql += "ORDER BY[A].[FIRST_SUBMIT_DATE]       ";
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataReader sdr = cmd.ExecuteReader();
            string zuomianmulu = DateTime.Now.ToString("yyyy-MM-dd") + "—" + DateTime.Now.ToString("HH-mm-ss") + "—" + comboBoxproduct1.Text;
            if (sdr.HasRows)
            {
                string message = "", messagefinal = "", mulu = "", files = "";
                DirectoryInfo dinfo = null;
                dinfo = new DirectoryInfo(@"\\172.16.1.204\DEPLOY_Temp\" + comboBoxproduct1.Text);

                Dir2_Load();
                if (comboBox10.Items.Count == 0)
                {
                    MessageBox.Show("是不是版本选错了，此版本无编译文件！");
                    sdr.Close();
                    return;
                }
                while (sdr.Read())
                {

                    foreach (String item in comboBox10.Items)
                    {
                        if (item.Contains(sdr[0].ToString()))
                        {
                            files = item;
                            message = item + "____" + sdr[1].ToString() + "；";
                        }
                    }
                    if (checkBox5.Checked)
                    {
                        mulu = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                        copyDirectory(dinfo + "\\" + files, mulu + "\\一键提取文件" + zuomianmulu);
                    }
                    if (checkBox6.Checked)
                    {
                        mulu = comboBox6.Text;
                        copyDirectory(dinfo + "\\" + files, mulu);
                    }
                    if (mulu == "")
                    {
                        MessageBox.Show("请选择你需要提取到的路径。");
                        return;
                    }
                    messagefinal += message;
                }
                messagefinal += "\r\n已成功提取。";
                MessageBox.Show(messagefinal);
                sdr.Close();
            }
            else
            {
                MessageBox.Show("检查一下版本，此版本没有你要提取的签出入单！");
                sdr.Close();
                return;
            }
        }

        private void button62_Click(object sender, EventArgs e) // 提取单支编译
        {
            if (comboBox10.Text == "")
            {
                return;
            }
            string dirE10_1 = "", dirE10_2, dirE10_3;
            /**
            if (comboBoxproduct1.Text == "E10_2.0")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_2.0\\";
            }
            if (comboBoxproduct1.Text == "E10_1.1.1")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_1.1.1\\";
            }
            if (comboBoxproduct1.Text == "DS_1.0")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\DS_1.0\\";
            }
            if (comboBoxproduct1.Text == "CM_1.1")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\CM_1.1\\";
            }
            if (comboBoxproduct1.Text == "E10_ALEX111")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_ALEX111\\";
            }
            if (comboBoxproduct1.Text == "E10_HJDZ111")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_HJDZ11\\";
            }
            if (comboBoxproduct1.Text == "E10_NBXL111")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_NBXL111\\";
            }
            if (comboBoxproduct1.Text == "E10_QTDG111")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_QTDG111\\";
            }
            if (comboBoxproduct1.Text == "E10_TCV111")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_TCV111\\";
            }
            if (comboBoxproduct1.Text == "E10_WJBZ111")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_WJBZ111\\";
            }
            if (comboBoxproduct1.Text == "E10_BAKE20")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_BAKE20\\";
            }
            if (comboBoxproduct1.Text == "E10_1.1.1_B")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\E10_1.1.1_B\\";
            }
            if (comboBoxproduct1.Text == "SRMS_2.0")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\SRMS_2.0\\";
            }
            if (comboBoxproduct1.Text == "SRMS_BAKE20")
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\SRMS_BAKE20\\";
            }
             **/
            if (check_bak.Checked)
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp_BAK\\" + comboBoxproduct1.Text + "\\";
            }
            else
            {
                dirE10_1 = "\\\\172.16.1.204\\DEPLOY_Temp\\" + comboBoxproduct1.Text + "\\";
            }
            if (checkBox5.Checked)
            {
                dirE10_2 = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                copyDirectory(dirE10_1 + comboBox10.Text, dirE10_2 + "\\" + comboBox10.Text);
                MessageBox.Show("成功提取" + comboBox10.Text + "到桌面");
            }
            if (checkBox6.Checked)
            {
                dirE10_3 = comboBox6.Text;
                copyDirectory(dirE10_1 + comboBox10.Text, dirE10_3);
                MessageBox.Show("成功提取" + comboBox10.Text + "到平台");
            }

        }

        private void button2_Click(object sender, EventArgs e)   //刷新
        {
            comboBox10.Text = "";
            Dir2_Load();
        }

        private void check_bak_CheckedChanged(object sender, EventArgs e)
        {
            comboBox10.Text = "";
            Dir2_Load();
        }

        #endregion

        #region 托盘

        //程序最小化
        private void size_Changed(object sender, EventArgs e)
        {
            //if (this.WindowState == FormWindowState.Minimized) //判断是否最小化
            //{
            //    frmconfig.Hide();
            //}
            //if (this.WindowState == FormWindowState.Normal) //判断是否正常化
            //{
            //    frmconfig.Show();
            //}
        }

        //当用户点击窗体右上角X按钮或(Alt + F4)时
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //HotKey.UnregisterHotKey(Handle, 100);
            if (e.CloseReason == CloseReason.UserClosing)//当用户点击窗体右上角X按钮或(Alt + F4)时 发生
            {
                e.Cancel = true;
                //this.ShowInTaskbar = false;
                //this.notifyIcon1.Visible = true;
                notifyIcon1.BalloonTipTitle = "程序已最小化";
                notifyIcon1.BalloonTipText = "程序还在继续运行......" + "\r\n" + "双击托盘图标还原窗口.";
                notifyIcon1.ShowBalloonTip(2000);
                this.Visible = false;

            }
        }

        //双击还原窗体
        private void notifyIcon1_Click(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)
            {
                this.WindowState = FormWindowState.Normal;
                this.Activate();
                this.Focus();
            }
            if (this.Visible == false)
            {
                this.Visible = true;
                this.Activate();
                this.Focus();
            }
        }

        //实现重新显示窗体
        private void 显示ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)
            {
                this.WindowState = FormWindowState.Normal;
                this.Activate();
                this.Focus();
            }
            if (this.Visible == false)
            {
                this.Visible = true;
                this.Activate();
                this.Focus();
            }
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            if (client != null)
            {

                if (client.Client.Connected)
                {
                    AsyncSendMessage("Logout," + textBoxUserName.Text);
                    br.Close();
                    bw.Close();
                }
                isExit = true;
                client.Close();
            }

            Application.Exit();

        }

        #endregion

        #region 自动登录
        //自动登录
        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll")]
        private static extern bool SetForegroundWindow(IntPtr hWnd);
        [DllImport("user32.dll")]
        static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern IntPtr GetForegroundWindow();   //WINAPI 获取当前活动窗体的句柄

        [DllImport("User32.dll", EntryPoint = "SendMessage")]
        private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);

        const int WM_KEYDOWN = 0x0100;//按键按下
        const int WM_KEYUP = 0x0101;//按键放开
        const int WM_SETTEXT = 0x000C;//发送文本
        const int WM_CLICK = 0x00F5;//鼠标点击
        const int WM_SETFOCUS = 0x0007;//设置焦点参数

        public void login(String user, String password)
        {
            if (checkBox9.Checked == true)
            {
                string _user = user;
                string _password = password;
                IntPtr hWnd1 = FindWindow(null, "登录");                         //  
                SetForegroundWindow(hWnd1);
                //MessageBox.Show(GetForegroundWindow().ToString("X"));
                IntPtr hWnd2 = FindWindowEx(hWnd1, IntPtr.Zero, null, null);

                IntPtr hWnd3 = FindWindowEx(hWnd2, IntPtr.Zero, null, "常规");       // 
                //MessageBox.Show(hWnd2.ToString("X"));

                IntPtr hWnd31 = FindWindowEx(hWnd3, IntPtr.Zero, "WindowsForms10.EDIT.app.0.bf7771", null); // 
                //MessageBox.Show(hWnd31.ToString("X"));
                IntPtr hWnd32 = FindWindowEx(hWnd3, IntPtr.Zero, "WindowsForms10.EDIT.app.0.bf7771", null);      // 
                //MessageBox.Show(hWnd32.ToString("X"));
                if ((int)hWnd32 == 0)
                {
                    hWnd31 = FindWindowEx(hWnd3, IntPtr.Zero, "WindowsForms10.EDIT.app.0.3d893c", null); // 
                    //MessageBox.Show(hWnd31.ToString("X"));
                    hWnd32 = FindWindowEx(hWnd3, IntPtr.Zero, "WindowsForms10.EDIT.app.0.3d893c", null);      // 
                    //MessageBox.Show(hWnd32.ToString("X"));
                }
                if ((int)hWnd32 == 0)
                {
                    hWnd31 = FindWindowEx(hWnd3, IntPtr.Zero, "WindowsForms10.EDIT.app.0.2004eee", null); // 
                    //MessageBox.Show(hWnd31.ToString("X"));
                    hWnd32 = FindWindowEx(hWnd3, IntPtr.Zero, "WindowsForms10.EDIT.app.0.2004eee", null);      // 
                    //MessageBox.Show(hWnd32.ToString("X"));
                }
                if ((int)hWnd32 == 0)
                {
                    hWnd31 = FindWindowEx(hWnd3, IntPtr.Zero, "WindowsForms10.EDIT.app.0.21af1a5", null); // 
                    //MessageBox.Show(hWnd31.ToString("X"));
                    hWnd32 = FindWindowEx(hWnd3, IntPtr.Zero, "WindowsForms10.EDIT.app.0.21af1a5", null);      // 
                    //MessageBox.Show(hWnd32.ToString("X"));
                }


                //IntPtr hWnd3A = FindWindowEx(hWnd2, IntPtr.Zero, "AliEdit", null);        // 
                //IntPtr hWnd3B = FindWindowEx(hWnd3A, IntPtr.Zero, "ATL:03B9F4A8", null);  // 
                //IntPtr hWnd3C = FindWindowEx(hWnd3B, IntPtr.Zero, "ATL:Edit", null);      // 
                //MessageBox.Show(hWnd33.ToString("X"));

                SendMessage(hWnd31, WM_SETTEXT, (IntPtr)0, _user);
                SendMessage(hWnd32, WM_SETTEXT, (IntPtr)0, _password);

                IntPtr hWnd4 = FindWindowEx(hWnd3, IntPtr.Zero, null, "登 录"); // 
                //MessageBox.Show(hWnd4.ToString("X"));

                SetForegroundWindow(hWnd4);
                SendKeys.Send("{ENTER}");
            }
            else
            {
                return;
            }
        }

        private void radioButton13_Click(object sender, EventArgs e)
        {
            _PWD = textBox34.Text;
        }

        private void radioButton14_Click(object sender, EventArgs e)
        {
            _PWD = textBox35.Text;
        }

        private void radioButton15_Click(object sender, EventArgs e)
        {
            _PWD = textBox36.Text;
        }

        private void radioButton16_Click(object sender, EventArgs e)
        {
            _PWD = textBox37.Text;
        }

        private void checkBox9_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox9.Checked == true)
            {
                radioButton13.Enabled = true;
                radioButton14.Enabled = true;
                radioButton15.Enabled = true;
                radioButton16.Enabled = true;
                radioButton13.Checked = true;
            }
            else
            {
                radioButton13.Checked = false;
                radioButton14.Checked = false;
                radioButton15.Checked = false;
                radioButton16.Checked = false;
                radioButton13.Enabled = false;
                radioButton14.Enabled = false;
                radioButton15.Enabled = false;
                radioButton16.Enabled = false;
            }
        }
        #endregion

        #region 数据库

        #region 定义全局变量
        private static string strServer = "";  //SQL服务器
        private static string strUID = "";     //登录用户
        private static string strPwd = "";     //登录密码
        private static string strDatabase = "";//要执行操作的数据库名
        #endregion

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            strDatabase = e.Node.Text;
            if (strDatabase.Contains("服务器："))
            {
                button21.Enabled = button32.Enabled = button34.Enabled = button78.Enabled = false;
            }
            else
            {
                button21.Enabled = button32.Enabled = button34.Enabled = button78.Enabled = true;
                label37.Text = "你选择的是" + strDatabase + "数据库";
            }
        }

        private void toolStripTextBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                toolStripTextBox3.Focus();
        }

        private void toolStripTextBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                toolStripButton1_Click(sender, e);
        }

        //登录SQL服务器
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            treeView1.Nodes.Clear();
            try
            {
                strServer = toolStripTextBox1.Text;
                strUID = toolStripTextBox2.Text;
                strPwd = toolStripTextBox3.Text;
                string str1 = "Data Source=" + strServer + ";database=master;Uid=" + strUID + ";Pwd=" + strPwd + ";";
                TreeNode TNode = new TreeNode("服务器：" + strServer);
                DataTable myTable = getTable(str1, "select name from sysdatabases", "sysdatabases");
                for (int i = 0; i < myTable.Rows.Count; i++)
                    TNode.Nodes.Add(myTable.Rows[i]["name"].ToString());
                treeView1.Nodes.Add(TNode);
                label37.Text = "服务器已连接。";
                //存储到DefaultData.xml
                doc.Load("DefaultData.xml");
                XmlNode nd = doc.SelectSingleNode("//Datebase_Server");
                nd.InnerText = toolStripTextBox1.Text;
                nd = doc.SelectSingleNode("//Pwd");
                nd.InnerText = toolStripTextBox3.Text;
                doc.Save("DefaultData.xml");
                //存储到DataServer
                doc.Load("DataServer.xml");
                nd = doc.SelectSingleNode("DataServer");
                XmlNodeList nl = nd.ChildNodes;
                foreach (XmlNode nd_Server in nl)
                {
                    if (nd_Server.Attributes[0].Value == toolStripTextBox1.Text)
                    {
                        nd_Server.Attributes[2].Value = toolStripTextBox3.Text;
                        doc.Save("DataServer.XML");
                        return;
                    }
                }
                XmlElement xmlelem = doc.CreateElement("Server");
                xmlelem.SetAttribute("IP", toolStripTextBox1.Text);
                xmlelem.SetAttribute("AC", toolStripTextBox2.Text);
                xmlelem.SetAttribute("PWD", toolStripTextBox3.Text);
                nd.AppendChild(xmlelem);
                doc.Save("DataServer.XML");

            }
            catch 
            {
                MessageBox.Show("连接失败，请检查网络、用户名、密码！");
            }
        }

        private void toolStripTextBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            doc.Load("DataServer.xml");

            XmlNodeList nl;
            nl = doc.SelectNodes("/DataServer/Server");
            foreach(XmlNode nd in nl)
            {
                if (nd.Attributes[0].Value == toolStripTextBox1.Text)
                {
                    toolStripTextBox2.Text = nd.Attributes[1].Value;
                    toolStripTextBox3.Text = nd.Attributes[2].Value;
                }
            }
        }
        //断开连接
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            sqlcon.Close();
            label37.Text = "服务器已断开。";
            treeView1.Nodes.Clear();
        }
        //选择备份文件的存放路径
        private void button32_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                textBox27.Text = folderBrowserDialog1.SelectedPath;
        }

        //备份数据库
        private void button21_Click(object sender, EventArgs e)
        {
            string filepath = "";
            if (textBox27.Text.EndsWith("\\"))
                filepath = textBox27.Text + textBox26.Text.Trim() + ".bak";
            else
                filepath = textBox27.Text + "\\" + textBox26.Text.Trim() + ".bak";
            if (!System.IO.File.Exists(filepath))
            {
                con = new SqlConnection();		//利用代码实现连接数据库
                con.ConnectionString = "Data Source=" + strServer + ";Database=" + strDatabase + ";uid=" + strUID + ";pwd=" + strPwd + ";";
                con.Open();
                SqlCommand com = new SqlCommand();
                com.CommandText = "BACKUP DATABASE " + strDatabase + " TO DISK = '" + filepath + "'with COMPRESSION";  //@"backup database test to disk='D:\backup' with init";

                com.Connection = con;	//连接
                com.ExecuteNonQuery();	//执行
                con.Close();
                MessageBox.Show("数据库备份成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("请重新命名！", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        //选择要还原的数据库文件
        private void button78_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "*.bak(备份文件)|*.bak|*.*(所有文件)|*.*";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox28.Text = openFileDialog1.FileName;
            }
        }

        //还原数据库
        private void button34_Click(object sender, EventArgs e)
        {
            string path = textBox28.Text;//获得备份文件路径
            if (path != "" && strDatabase != "")
            {
                string SqlStr1 = "Data Source=" + strServer + ";Database=" + "master" + ";uid=" + strUID + ";pwd=" + strPwd + ";";
                string SqlStr2 = "use master restore database " + strDatabase + " from disk='" + path + "'";
                string SqlStr3 = "backup log " + strDatabase + " to disk='" + path + "' use master restore database " + strDatabase + " from disk='" + path + "'";
                string single1 = "alter database " + strDatabase + " set single_user with rollback immediate " + SqlStr2;
                string single2 = "alter database " + strDatabase + " set single_user with rollback immediate " + SqlStr3;
                using (SqlConnection con1 = new SqlConnection(SqlStr1))
                {
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandTimeout = 360;
                    cmd.Connection = con1;
                    con1.Open();
                    //KILL DataBase Process
                    cmd = new SqlCommand("SELECT spid FROM sysprocesses ,sysdatabases WHERE sysprocesses.dbid=sysdatabases.dbid AND sysdatabases.Name='" + strDatabase + "'", con1);
                    SqlDataReader dr;
                    dr = cmd.ExecuteReader();
                    ArrayList list = new ArrayList();
                    while (dr.Read())
                    {
                        list.Add(dr.GetInt16(0));
                    }
                    dr.Close();
                    for (int i = 0; i < list.Count; i++)
                    {
                        cmd = new SqlCommand(string.Format("KILL {0}", list[i]), con1);
                        cmd.ExecuteNonQuery();
                    }

                    SqlCommand cmdRT = new SqlCommand();
                    cmdRT.CommandType = CommandType.Text;
                    cmdRT.Connection = con1;
                    cmdRT.CommandText = @"restore database " + strDatabase + " from disk='" + path + "'with replace";

                    try
                    {
                        cmdRT.ExecuteNonQuery();
                        MessageBox.Show("Restore successed.");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        con1.Close();
                    }
                }
            }
        }
        /// <summary>
        /// 更改数据库密码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void changePassWord_Click(object sender, EventArgs e)
        {
            if (strDatabase != "")
            {
                string SqlStr1 = "Data Source=" + strServer + ";Database=" + strDatabase + ";uid=" + strUID + ";pwd=" + strPwd + ";";
                using (SqlConnection con1 = new SqlConnection(SqlStr1))
                {
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = con1;
                    con1.Open();
                    cmd = new SqlCommand("update [USER] SET SECURITYIDENTITY= '" + "185451121164982152415142385317824716511623146175163" + "'" + "where LOGONNAME= '" + "dcms" + "'", con1);
                    int temp = cmd.ExecuteNonQuery();
                    if (temp > 0)
                    {
                        MessageBox.Show("修改成功");//WinForm
                    }
                    con1.Close();
                }
            }
        }
        // 获得数据表结构
        /// <summary>
        /// 获得数据表结构
        /// </summary>
        /// <param name="strCon">连接字符串</param>
        /// <param name="strSql">SQL语句</param>
        /// <param name="strTable">数据表名</param>
        /// <returns>DataTable类型</returns>
        private DataTable getTable(string strCon, string strSql, string strTable)
        {
            try
            {
                sqlcon = new SqlConnection(strCon);
                SqlDataAdapter da = new SqlDataAdapter(strSql, sqlcon);
                DataTable dt = new DataTable(strTable);
                da.Fill(dt);
                return dt;
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region 快捷键
        protected override void WndProc(ref Message m)
        {

            switch (m.WParam.ToInt64())
            {
                case 100:
                    if (this.WindowState == FormWindowState.Minimized)
                    {
                        this.WindowState = FormWindowState.Normal;
                        this.Activate();
                        this.Focus();

                        //this.TopMost = true;
                        break;
                    }
                    if (this.Visible == false)
                    {
                        this.Visible = true;
                        //this.TopMost = true;
                        this.Activate();
                        this.Focus();

                    }
                    else if (this.Visible == true)
                    {
                        this.Visible = false;
                    }
                    break;
                case 200:
                    System.Threading.Thread.Sleep(1000);
                    SendKeys.SendWait(textBox51.Text);
                    System.Threading.Thread.Sleep(1000);
                    SendKeys.SendWait("{TAB}");
                    System.Threading.Thread.Sleep(1000);
                    SendKeys.SendWait(textBox52.Text);
                    System.Threading.Thread.Sleep(1000);
                    SendKeys.SendWait("{ENTER}");
                    break;
                case 300:
                    DataTable dt = LoadDataFromExcel(textBox53.Text);
                    int rows = dt.Rows.Count;
                    //System.Threading.Thread.Sleep(500);
                            SendKeys.SendWait("+");
                    for (i = 0; i <= rows; i++)
                    {
                        //if (System.Console.KeyAvailable)//如果有键按下

                        //{

                        ////keyInfo = System.Console.ReadKey(true);//读取

                        ////if (keyInfo.KeyChar 0x1b)//判断

                        ////a = true;
                        //    break;

                        //}
                        if (dt.Rows[i][0].ToString() != "")
                        {                         
                            System.Threading.Thread.Sleep(500);
                            SendKeys.SendWait(dt.Rows[i][0].ToString());
                            System.Threading.Thread.Sleep(500);
                            SendKeys.SendWait("{TAB}");
                            System.Threading.Thread.Sleep(500);
                            SendKeys.SendWait("{TAB}");
                            System.Threading.Thread.Sleep(500);
                            SendKeys.SendWait("{TAB}");
                            System.Threading.Thread.Sleep(500);
                            SendKeys.SendWait("{TAB}");
                            //System.Threading.Thread.Sleep(500);
                            //SendKeys.SendWait("{TAB}");
                            //System.Threading.Thread.Sleep(500);
                            //SendKeys.SendWait("{TAB}");
                            System.Threading.Thread.Sleep(500);
                            SendKeys.SendWait(dt.Rows[i][1].ToString());
                            System.Threading.Thread.Sleep(500);
                            SendKeys.SendWait("{TAB}");
                            System.Threading.Thread.Sleep(500);
                            SendKeys.SendWait(dt.Rows[i][2].ToString() + ":" + dt.Rows[i][3].ToString());
                            System.Threading.Thread.Sleep(500);
                            SendKeys.SendWait("{TAB}");
                            System.Threading.Thread.Sleep(500);
                            SendKeys.SendWait(dt.Rows[i][2].ToString());
                            System.Threading.Thread.Sleep(500);
                            SendKeys.SendWait("{TAB}");
                            System.Threading.Thread.Sleep(500);
                            SendKeys.SendWait("{TAB}");
                            System.Threading.Thread.Sleep(500);
                            SendKeys.SendWait("{TAB}");
                            System.Threading.Thread.Sleep(500);
                            SendKeys.SendWait("{TAB}");

                        }
                        else
                        {
                            break;
                        }
                        if (flag)
                        {
                            break;
                        }
                    }
                    flag = false;
                    break;
                case 400:
                    flag = true;
                    break;
                case 500:
                     Process[] ps = Process.GetProcesses();
                    foreach (Process item in ps)
                    {
                        if (item.ProcessName == "Digiwin.Mars.ServerStart")
                        {
                            item.Kill();
                        }
                        if (item.ProcessName == "Digiwin.Mars.ClientStart")
                        {
                            if (item.MainModule.FileName != textBox25.Text + "\\Digiwin.Mars.ClientStart.exe")
                            {
                                item.Kill();
                            }
                        }

                    }
                    break;
            }
            base.WndProc(ref m);
        }

        public DataTable LoadDataFromExcel(string Path)
        {
            //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "data source=" + Path + ";Extended Properties='Excel 8.0; HDR=YES; IMEX=1'";
            string strConn = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source=" + Path + ";Extended Properties='Excel 12.0; HDR=Yes; IMEX=1'";
            OleDbConnection conn = new OleDbConnection(strConn);
            conn.Open();
            string strExcel = "";
            OleDbDataAdapter myCommand = null;
            DataTable dt = null;
            strExcel = "select * from [sheet1$]";
            myCommand = new OleDbDataAdapter(strExcel, strConn);
            dt = new DataTable();
            myCommand.Fill(dt);
            conn.Close();
            return dt;
        }
        #endregion

        #region 记录目录到dir和读取目录
        private void WriteTxt(string S,string file)
        {
            var Current = Directory.GetCurrentDirectory();//获取当前根目录
            //true是追加方式，false是覆盖方式
            StreamWriter w = new StreamWriter(Current + "\\" + file , true);
            w.WriteLine(S, Encoding.UTF8);
            w.Flush();
            w.Close();

        }
        private void ReadText(string file)
        {
            var Current = Directory.GetCurrentDirectory();//获取当前根目录
            //true是追加方式，false是覆盖方式
            StreamReader w = new StreamReader(Current + "\\"+ file , true);
            string strLine = string.Empty;
            while ((strLine = w.ReadLine()) != null)
            {
                comboBox6.Items.Add(strLine);
            }
        }

        #endregion

        #region 订饭

        public void transferMenu(string menu)
        {
            if (menu == "")
            {
                AsyncSendMessage("Order," + Dns.GetHostName() + "," + "随便点");
            }
            else if (menu == "不订")
            {
                AsyncSendMessage("NoOrder," + Dns.GetHostName());
            }
            else
            {
                AsyncSendMessage("Order," + Dns.GetHostName() + "," + menu);
            }
        }

        #endregion

        #region 简单部署
        //上引下推和向导式批次目前不支持
        private void 更新到平台_Click(object sender, EventArgs e)
        {
            if (Directory.Exists(comboBox6.Text + "\\Server-new\\"))
            {
                System.IO.Directory.Move(comboBox6.Text + "\\Server-new\\", comboBox6.Text + "\\Server\\");
            }
            string mulu = "";
            string mulu1 = "";
            string client = "";
            if (_Version == "2.0")
            {
                client = "\\DeployServer\\Shared";
            }
            else
            {
                client = "\\Client";
            }
            if (comboBoxproduct1.Text != "E10_2.0" & comboBoxproduct1.Text != "E10_1.1.1" &
                comboBoxproduct1.Text != "CM_1.1" & comboBoxproduct1.Text != "DS_1.0" &
                comboBoxproduct1.Text != "E10_1.1.1_B" & comboBoxproduct1.Text != "SRMS_2.0" &
                comboBoxproduct1.Text != "SRMS_BAKE20")
            {
                mulu = "\\Customization";
            }
            if (comboBoxproduct1.Text == "E10_2.0" || comboBoxproduct1.Text == "E10_HJDZ20")
            {
                mulu1 = "\\Application";
            }
            DirectoryInfo dinfo = new DirectoryInfo(dir_pick + comboBox2.Text);
            //获取指定目录下的所有子目录及文件类型
            FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
            if (comboBox1.Text == "Designer Project" || comboBox1.Text == "DataModel Project")
            {
                foreach (FileSystemInfo fsinfo in fsinfos)
                {
                    if (fsinfo is DirectoryInfo)    //判断是否文件夹
                    {
                        if (!(fsinfo.Name.Equals("bin") || fsinfo.Name.Equals("TEMP") || fsinfo.Name.Equals("Client") || fsinfo.Name.Equals("Server")
                            || fsinfo.Name.Equals("ServiceSpec")))
                        {
                            dinfo = new DirectoryInfo(dir_pick + comboBox2.Text + "\\" + fsinfo.Name);
                            FileSystemInfo[] fsinfos1 = dinfo.GetFileSystemInfos();
                            foreach (FileSystemInfo fsinfo1 in fsinfos1)
                            {
                                if (fsinfo1 is DirectoryInfo)    //判断是否文件夹
                                {

                                }
                                else
                                {
                                    if (fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "CSDdcxml" || fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "BDSdcxml" || fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "FDdcxml" || fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "SWDdcxml" || fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "GVDdcxml")
                                    {

                                        string[] sp = fsinfo1.Name.Split('.');
                                        if (sp[1].Equals(comboBox2.Text))
                                        {
                                            System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + client + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);

                                        }
                                        else
                                        {
                                            System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + client + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + "." + sp[1] + ".dcxml", true);

                                        }


                                    }

                                    if (fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "ETYdcxml")
                                    {
                                        string[] sp = fsinfo1.Name.Split('.');
                                        System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + client + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + "." + sp[1] + ".dcxml", true);
                                    }
                                    if (fsinfo1.FullName.Substring(
                               fsinfo1.FullName.LastIndexOf(".") + 1,
                               fsinfo1.FullName.Length -
                               fsinfo1.FullName.LastIndexOf(".") - 1) == "dcxml")
                                    {
                                        string[] sp = fsinfo1.Name.Split('.');
                                        if (sp[0] == "LayoutContainer" && sp[1].Equals(comboBox2.Text))
                                        {
                                            System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + client + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);

                                        }
                                        if (sp[0] == "LayoutContainer" && !sp[1].Equals(comboBox2.Text))
                                        {
                                            System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + client + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + "." + sp[1] + ".dcxml", true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "MRDdcxml" || fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "QPJdcxml")
                        {
                            string[] sp = fsinfo.Name.Split('.');
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + client + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);
                        }
                        if (fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "VDdcxml")
                        {
                            string[] sp = fsinfo.Name.Split('.');
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + "\\Server" + mulu1 + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);
                        }
                        if (fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "ETYdcxml")
                        {
                            string[] sp = fsinfo.Name.Split('.');
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + "\\Server" + mulu1 + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + client + mulu + "\\BusinessObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);
                        }
                        if (fsinfo.FullName.Substring(
                  fsinfo.FullName.LastIndexOf(".") + 1,
                  fsinfo.FullName.Length -
                  fsinfo.FullName.LastIndexOf(".") - 1) == "DMdcxml")
                        {
                            string[] sp = fsinfo.Name.Split('.');
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + "\\Server" + mulu1 + mulu + "\\BusinessObjects\\DataModel\\" + sp[0] + "." + sp[1] + ".dcxml", true);
                        }
                    }
                }
                MessageBox.Show("已更新");
            }
            if (comboBox1.Text == "Batch Project")
            {
                foreach (FileSystemInfo fsinfo in fsinfos)
                {
                    if (fsinfo is DirectoryInfo)    //判断是否文件夹
                    {
                        if (!(fsinfo.Name.Equals("bin") || fsinfo.Name.Equals("TEMP") || fsinfo.Name.Equals("Client") || fsinfo.Name.Equals("Server")
                            || fsinfo.Name.Equals("ServiceSpec")))
                        {
                            dinfo = new DirectoryInfo(dir_pick + comboBox2.Text + "\\" + fsinfo.Name);
                            FileSystemInfo[] fsinfos1 = dinfo.GetFileSystemInfos();
                            foreach (FileSystemInfo fsinfo1 in fsinfos1)
                            {
                                if (fsinfo1 is DirectoryInfo)    //判断是否文件夹
                                {

                                }
                                else
                                {
                                    if (fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "CSDdcxml" || fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "BDSdcxml" || fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "FDdcxml" || fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "SWDdcxml" || fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "GVDdcxml")
                                    {

                                        string[] sp = fsinfo1.Name.Split('.');
                                        if (sp[1].Equals(comboBox2.Text))
                                        {
                                            System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + client + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);

                                        }
                                        else
                                        {
                                            System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + client + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + "." + sp[1] + ".dcxml", true);

                                        }


                                    }

                                    if (fsinfo1.FullName.Substring(
                                fsinfo1.FullName.LastIndexOf(".") + 1,
                                fsinfo1.FullName.Length -
                                fsinfo1.FullName.LastIndexOf(".") - 1) == "ETYdcxml")
                                    {
                                        string[] sp = fsinfo1.Name.Split('.');
                                        System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + client + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + "." + sp[1] + ".dcxml", true);
                                    }
                                    if (fsinfo1.FullName.Substring(
                               fsinfo1.FullName.LastIndexOf(".") + 1,
                               fsinfo1.FullName.Length -
                               fsinfo1.FullName.LastIndexOf(".") - 1) == "dcxml")
                                    {
                                        string[] sp = fsinfo1.Name.Split('.');
                                        if (sp[0] == "LayoutContainer" && sp[1].Equals(comboBox2.Text))
                                        {
                                            System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + client + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);

                                        }
                                        if (sp[0] == "LayoutContainer" && !sp[1].Equals(comboBox2.Text))
                                        {
                                            System.IO.File.Copy(fsinfo1.FullName, comboBox6.Text + client + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + "." + sp[1] + ".dcxml", true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "MRDdcxml" || fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "QPJdcxml")
                        {
                            string[] sp = fsinfo.Name.Split('.');
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + client + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);
                        }
                        if (fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "VDdcxml" || fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "BAHdcxml")
                        {
                            string[] sp = fsinfo.Name.Split('.');
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + "\\Server" + mulu1 + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);
                        }
                        if (fsinfo.FullName.Substring(
                   fsinfo.FullName.LastIndexOf(".") + 1,
                   fsinfo.FullName.Length -
                   fsinfo.FullName.LastIndexOf(".") - 1) == "ETYdcxml")
                        {
                            string[] sp = fsinfo.Name.Split('.');
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + "\\Server" + mulu1 + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + client + mulu + "\\BatchObjects\\" + comboBox2.Text + "\\" + sp[0] + ".dcxml", true);
                        }
                        if (fsinfo.FullName.Substring(
                  fsinfo.FullName.LastIndexOf(".") + 1,
                  fsinfo.FullName.Length -
                  fsinfo.FullName.LastIndexOf(".") - 1) == "DMQdcxml")
                        {
                            string[] sp = fsinfo.Name.Split('.');
                            System.IO.File.Copy(fsinfo.FullName, comboBox6.Text + "\\Server" + mulu1 + mulu + "\\BatchObjects\\" + sp[0] + "." + sp[1] + ".dcxml", true);
                        }
                    }
                }
                MessageBox.Show("已更新");
            }
            if (comboBox1.Text == "Report Project")
            {
                //预留报表
            }
        }

        #endregion

        #region 更改IIS物理路径

        private void comboBox6_SelectedValueChanged(object sender, EventArgs e)
        {
            Version();
            //WritePrivateProfileString(strOne, "Data Source", comboBox6.Text, str);
            doc.Load("DefaultData.xml");
            XmlNode nd = doc.SelectSingleNode("//Data_Source");
            nd.InnerText = comboBox6.Text;
            doc.Save("DefaultData.xml");
            //Process.Start("c:\\windows\\system32\\inetsrv\\appcmd.exe", "set app /app.name: " + "\"" + textBox38.Text + "/" + textBox39.Text + "\"" + " /[path='/'].physicalpath:" + "\"" + comboBox6.Text + "\\" + textBox39.Text + "\"");
            string cmd = "c:\\windows\\system32\\inetsrv\\appcmd.exe set app /app.name: " + "\"" + textBox38.Text + "/" + textBox39.Text + "\"" + " /[path='/'].physicalpath:" + "\"" + comboBox6.Text + "\\WebServer" + "\"";
            //Console.WriteLine(Execute(cmd, 0).ToString());
            Execute(cmd, 0);
            Dir1_Load(sender, e);   //刷新PickList、buniessType
            ReadConfig();          //读取环境的连接配置
            if (!System.IO.Directory.Exists(comboBox6.Text))
            {
                MessageBox.Show("本地平台路径已不存在，请更换本地平台路径！");
                button7.Enabled = false;
            }
            else
            {
                button7.Enabled = true;
            }
            if (!System.IO.Directory.Exists(comboBox6.Text + "\\Server\\"))
            {
                button3.Enabled = false;
                button5.Enabled = false;
                button59.Enabled = false;
                button60.Enabled = false;
                button62.Enabled = false;
                comboBox15.Enabled = false;
                comboBox16.Enabled = false;
                //checkBox10.Checked = false;
                dataGridView3.Enabled = false;
            }
            else
            {
                button3.Enabled = true;
                button5.Enabled = true;
                button59.Enabled = true;
                button60.Enabled = true;
                button62.Enabled = true;
                comboBox15.Enabled = true;
                comboBox16.Enabled = true;
                dataGridView3.Enabled = true;
            }
            //LoadType();
        }

        public static string Execute(string dosCommand, int outtime)
        {
            string output = "";
            if (dosCommand != null && dosCommand != "")
            {
                System.Diagnostics.Process process = new Process();//创建进程对象
                System.Diagnostics.ProcessStartInfo startinfo = new ProcessStartInfo();//创建进程时使用的一组值，如下面的属性
                startinfo.FileName = "cmd.exe";//设定需要执行的命令程序
                //以下是隐藏cmd窗口的方法
                startinfo.Arguments = "/c" + dosCommand;//设定参数，要输入到命令程序的字符，其中"/c"表示执行完命令后马上退出
                startinfo.UseShellExecute = false;      //不使用系统外壳程序启动
                startinfo.RedirectStandardInput = false;//不重定向输入
                startinfo.RedirectStandardOutput = true;//重定向输出，而不是默认的显示在dos控制台上
                startinfo.CreateNoWindow = true;        //不创建窗口
                process.StartInfo = startinfo;
                try
                {
                    if (process.Start())        //开始进程
                    {
                        if (outtime == 0)
                        {
                            process.WaitForExit();
                        }
                        else
                        {
                            process.WaitForExit(outtime);
                        }
                        output = process.StandardOutput.ReadToEnd();//读取进程的输出
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
                finally
                {
                    if (process != null)
                    {
                        process.Close();
                    }
                }
            }
            return output;
        }

        #endregion

        #region 记录产品群组到Product和读取产品群组
        private void WriteProduct(string S)
        {
            bool flag = false;
            foreach (object list in comboBoxproduct.Items)
            {
                if (S.Equals(list))
                {
                    flag = true;
                }
            }

            if (!flag)
            {
                var Current = Directory.GetCurrentDirectory();//获取当前根目录
                //true是追加方式，false是覆盖方式
                StreamWriter w = new StreamWriter(Current + "\\product.txt", true);
                w.WriteLine(S, Encoding.UTF8);
                w.Flush();
                w.Close();
            }
        }
        private void ReadProduct(ComboBox combox)
        {
            var Current = Directory.GetCurrentDirectory();//获取当前根目录
            //true是追加方式，false是覆盖方式
            StreamReader w = new StreamReader(Current + "\\product.txt", true);
            string strLine = string.Empty;
            while ((strLine = w.ReadLine()) != null)
            {
                bool flag = false;
                foreach (object list in combox.Items)
                {
                    if (strLine.Equals(list))
                    {
                        flag = true;
                    }
                }

                if (!flag)
                {
                    combox.Items.Add(strLine);
                }
            }
            w.Close();
        }
        #endregion

        #region 判断平台版本
        public void Version()
        {
            if (Directory.Exists(comboBox6.Text + "\\Server\\Control\\"))
            {
                _Version = "2.0";
            }
            else
            {
                _Version = "1.1.1";
            }
        }
        #endregion

        #region [函数]
        /// <summary>
        /// 检索到的DataTable
        /// </summary>
        private DataTable dtFileName = null;
        /// <summary>
        /// 待检索的文件夹
        /// </summary>
        private FileSystemInfo FsInfoNeedScan = null;
        /// <summary>
        /// 待检索的文件名
        /// </summary>
        private string strFileNameNeedScan = "";
        /// <summary>
        /// 是否模糊查询
        /// </summary>
        private bool bIsFuzzyQueryNeedScan = false;
        /// <summary>
        /// 是否按照内容查询
        /// </summary>
        private bool bIsContentQueryNeedScan = false;
        /// <summary>
        /// 检索方式：全盘/指定文件夹
        /// </summary>
        private int iTypeNeedScan = 0;
        /// <summary>
        /// 检索线程
        /// </summary>
        private Thread thScanOne = null;

        #endregion

        #region [方法]

        #region [窗体方法]
        /// <summary>
        /// 设置控件Visible属性
        /// </summary>
        /// <param name="bVisible"></param>
        private void SetControlVisible(bool bVisible)
        {
            this.btnQueryDir.Visible = bVisible;
            //this.lblQueryDir.Visible = bVisible;
            // this.lblQueryDirMsg.Visible = bVisible;
        }

        /// <summary>
        /// 设置查询按钮是否可用
        /// </summary>
        /// <param name="bEnable"></param>
        private void SetQueryStartEnable(bool bEnable)
        {
            this.btniQueryStart.Enabled = bEnable;
            this.btnQueryDir.Enabled = bEnable;
            if (bEnable)//将查询界面恢复
            {
                //this.panel1.Size = new Size(741, 68);
            }
            else//将查询界面拉长
            {
                //this.panel1.Size = new Size(741, 116);
            }
        }

        /// <summary>
        /// 验证输入
        /// </summary>
        /// <returns></returns>
        private bool ValidateInput()
        {
            if (ttxFileName.Text.Trim() == "")
            {
                MessageBox.Show("请输入检索的文件名！");
                ttxFileName.Focus();
                return false;
            }
            if (lblQueryDir.Text == "")
            {
                MessageBox.Show("请选择待检索的文件夹！");
                btnQueryDir.Focus();
                return false;
            }
            return true;
        }
        #endregion

        #region [检索方法]
        /// <summary>
        /// 开始扫描
        /// </summary>
        private void StartThreadScan()
        {
            //判断是否模糊查询
            if (cbFix.Checked)
            {
                bIsFuzzyQueryNeedScan = true;
            }
            else
            {
                bIsFuzzyQueryNeedScan = false;
            }
            //判断是否查询文件内容
            if (cbFileContent.Checked)
            {
                bIsContentQueryNeedScan = true;
            }
            else
            {
                bIsContentQueryNeedScan = false;
            }


            switch (iTypeNeedScan)
            {
                case 1://全盘扫描
                    ArrayList alDisk = WindowsFun.GetDiskDriectoryInfo();
                    if (strFileNameNeedScan != "" && alDisk.Count > 0)//待检索的文件名不为空，硬盘盘符不为空
                    {
                        for (int i = 0; i < alDisk.Count; i++)//分别扫描每个盘符
                        {
                            DirectoryInfo diNew = new DirectoryInfo(alDisk[i].ToString() + "\\");//建立文件目录对象
                            StartRecurrenceScanFile(diNew, strFileNameNeedScan, bIsFuzzyQueryNeedScan);
                        }
                    }
                    break;
                case 2://指定文件夹扫描
                    //获取检索目录
                    DirectoryInfo dirInput = new DirectoryInfo(lblQueryDir.Text.Trim());
                    FsInfoNeedScan = (FileSystemInfo)dirInput;
                    StartRecurrenceScanFile(FsInfoNeedScan, strFileNameNeedScan, bIsFuzzyQueryNeedScan);
                    break;
            }
            SetCurrentFileNameToLabel("查询结束");
            SetEnableToQueryButton(true);//查询按钮可用
        }

        #region [单线程方法]

        #region [委托]
        /// <summary>
        /// 委托：发送检索到的文件名到DataGridView
        /// </summary>
        /// <param name="strScanFileName"></param>
        /// <param name="strScanFilePath"></param>
        delegate void SendFileNameToDataGridView(string strScanFileName, string strScanFilePath);
        /// <summary>
        /// 受委托的方法：发送检索到的文件名到DataGridView
        /// </summary>
        /// <param name="strFileText"></param>
        /// <param name="strFilePath"></param>
        private void SetFileNameToDataGridView(string strFileText, string strFilePath)
        {
            if (this.dgvData.InvokeRequired)
            {
                SendFileNameToDataGridView stlti = new SendFileNameToDataGridView(SetFileNameToDataGridView);
                this.Invoke(stlti, new object[] { strFileText, strFilePath });
            }
            else
            {
                if (dtFileName == null)
                {
                    dtFileName = new DataTable();
                    dtFileName.Columns.Add("文件名", typeof(string));
                    dtFileName.Columns.Add("所在文件夹", typeof(string));
                }
                //int iRow = dtFileName.Rows.Count;//获取行数
                DataRow dr = dtFileName.NewRow();
                dr[0] = strFileText;
                dr[1] = strFilePath;
                dtFileName.Rows.Add(dr);
                dgvData.DataSource = dtFileName;
            }
        }

        /// <summary>
        /// 委托：发送当前文件名到Label
        /// </summary>
        /// <param name="strScanCurrentFileName"></param>
        delegate void SendCurrentFileNameToLabel(string strScanCurrentFileName);
        /// <summary>
        /// 受委托的方法：发送当前文件名到Label
        /// </summary>
        /// <param name="strCurrentFileText"></param>
        private void SetCurrentFileNameToLabel(string strCurrentFileText)
        {
            if (this.lblScanFileMsg.InvokeRequired)
            {
                SendCurrentFileNameToLabel scfntl = new SendCurrentFileNameToLabel(SetCurrentFileNameToLabel);
                this.Invoke(scfntl, new object[] { strCurrentFileText });
            }
            else
            {
                this.lblScanFileMsg.Text = strCurrentFileText;
            }
        }

        /// <summary>
        /// 委托：发送Bool值到按钮状态
        /// </summary>
        /// <param name="strScanCurrentFileName"></param>
        delegate void SendEnableToQueryButton(bool bButtonEnable);
        /// <summary>
        /// 受委托的方法：发送Bool值到按钮状态
        /// </summary>
        /// <param name="bEnable"></param>
        private void SetEnableToQueryButton(bool bEnable)
        {
            if (this.lblScanFileMsg.InvokeRequired)
            {
                SendEnableToQueryButton setqb = new SendEnableToQueryButton(SetEnableToQueryButton);
                this.Invoke(setqb, new object[] { bEnable });
            }
            else
            {
                SetQueryStartEnable(bEnable);
            }
        }
        #endregion

        /// <summary>
        /// 递归查询文件夹中包含的文件
        /// </summary>
        /// <param name="FsScaninfo">待查文件夹</param>
        /// <param name="strInputFileName">待查文件名</param>
        /// <param name="bFuzzyQuery">是否模糊查询</param>
        private void StartRecurrenceScanFile(FileSystemInfo FsScaninfo, string strInputFileName, bool bFuzzyQuery)
        {
            if (!FsScaninfo.Exists) return;
            DirectoryInfo dir = FsScaninfo as DirectoryInfo;
            //不是目录 
            if (dir == null) return;
            try
            {
                FileSystemInfo[] files = dir.GetFileSystemInfos();
                for (int i = 0; i < files.Length; i++)
                {
                    FileInfo file = files[i] as FileInfo;
                    //是文件
                    if (file != null)
                    {
                        SetCurrentFileNameToLabel(file.FullName.ToString());//发送当前文件全名
                        string strScanedFileName = "";
                        string strScanedFilePath = "";
                        //按照内容查询
                        if (bIsContentQueryNeedScan)
                        {
                            bool bContentExsit = WindowsFun.ChargeFileExsitString(strInputFileName, file);
                            if (bContentExsit)
                            {
                                strScanedFileName = file.Name.ToString();
                                strScanedFilePath = file.DirectoryName.ToString();
                                SetFileNameToDataGridView(strScanedFileName, strScanedFilePath);
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else//按照名称查询
                        {
                            if (bFuzzyQuery)//模糊查询
                            {
                                if (file.Name.ToUpper().IndexOf(strInputFileName.ToUpper()) > -1)
                                {
                                    strScanedFileName = file.Name.ToString();
                                    strScanedFilePath = file.DirectoryName.ToString();
                                    SetFileNameToDataGridView(strScanedFileName, strScanedFilePath);
                                }
                            }
                            else//非模糊查询
                            {
                                if (file.Name.ToUpper() == strInputFileName.ToUpper())
                                {
                                    strScanedFileName = file.Name.ToString();
                                    strScanedFilePath = file.DirectoryName.ToString();
                                    SetFileNameToDataGridView(strScanedFileName, strScanedFilePath);
                                }
                            }
                        }
                    }
                    //对于子目录，进行递归调用 
                    else
                        StartRecurrenceScanFile(files[i], strInputFileName, bFuzzyQuery);
                }
            }
            catch { }
        }
        #endregion

        #region [多线程方法]

        #endregion

        #endregion
        #endregion

        #region [事件]

        #region [窗体界面事件]
        //private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        //{
        //    if (MessageBox.Show("确定退出软件？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
        //    {
        //        Environment.Exit(0);
        //    }
        //    else
        //    {
        //        e.Cancel = true;
        //    }
        //}

        private void cbFullDisk_CheckedChanged(object sender, EventArgs e)
        {
            if (cbFullDisk.Checked == false)
            {
                //this.groupBox1.Size = new Size(637, 54);
                //this.panel1.Size = new Size(741, 89);
                SetControlVisible(false);
                chkSpec.Checked = true;
                chkSpec.Enabled = true;
                chkSrc.Enabled = true;
                comboBox4.Visible = true;
                label9.Visible = true;
                comboBox4.SelectedIndex = 0;
            }
            else
            {
                //this.groupBox1.Size = new Size(532, 54);
                //this.panel1.Size = new Size(741, 68);
                SetControlVisible(true);
                chkSpec.Checked = false;
                chkSrc.Checked = false;
                chkSpec.Enabled = false;
                chkSrc.Enabled = false;
                doc.Load("DefaultData.xml");
                XmlNode nd = doc.SelectSingleNode("//CustomPath");
                lblQueryDir.Text = nd.InnerText;
                checktype = "";
                comboBox4.Visible = false;
                label9.Visible = false;
            }
        }

        private void dgvData_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            if (dgvData.Rows.Count > 0)
            {
                for (int i = 0; i < dgvData.Rows.Count; i++)
                {
                    int iRowNumber = i + 1;
                    dgvData.Rows[i].HeaderCell.Value = iRowNumber.ToString();
                }
            }
        }
        #endregion

        #region [鼠标点击事件]
        private void btniExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnQueryDir_Click(object sender, EventArgs e)
        {
            if (fbdQueryDir.ShowDialog() == DialogResult.OK)
            {
                lblQueryDir.Text = fbdQueryDir.SelectedPath;
                doc.Load("DefaultData.xml");
                XmlNode nd = doc.SelectSingleNode("//CustomPath");
                nd.InnerText = fbdQueryDir.SelectedPath;
                doc.Save("DefaultData.xml");
            }
        }

        private void btniQueryStart_Click(object sender, EventArgs e)
        {
            //dataGridView4.Visible = false;
            if (ValidateInput())
            {
                this.lblScanFileMsg.Text = "正在初始化搜索引擎...";
                if (dtFileName != null)
                {
                    dtFileName.Clear();
                    dgvData.DataSource = dtFileName;
                }
                SetQueryStartEnable(false);
                strFileNameNeedScan = ttxFileName.Text.Trim();//检索的文件名
                if (cbFullDisk.Checked)
                {
                    iTypeNeedScan = 2;
                    //全盘检索，则使用多线程分别检索
                }
                else
                {
                    iTypeNeedScan = 2;
                    //单线程检索
                }
                thScanOne = new Thread(StartThreadScan);
                thScanOne.Start();
            }
        }

        private void btniQueryEnd_Click(object sender, EventArgs e)
        {
            this.lblScanFileMsg.Text = "";
            if (thScanOne != null && thScanOne.IsAlive)
            {
                thScanOne.Abort();
            }
            SetQueryStartEnable(true);
        }

        private void dgvData_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (dgvData.Rows.Count > 0)
                {
                    cmsDgv.Show(dgvData, e.Location);
                }
            }
        }

        private void 打开文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                string strTmpCurrentPath = dgvData.CurrentRow.Cells[1].Value.ToString();
                string strTmpCurrentFileName = dgvData.CurrentRow.Cells[0].Value.ToString();
                更新规格ToolStripMenuItem_Click(sender, e);
                System.Diagnostics.Process pOneFile = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo infoOneFileOpen = new System.Diagnostics.ProcessStartInfo();
                if (strTmpCurrentPath.Split(':').Length == 1)
                {
                    int i = strTmpCurrentPath.IndexOf("WaitTest");
                    infoOneFileOpen.WorkingDirectory = "C:\\" + strTmpCurrentPath.Substring(i + 9) + "\\";
                }
                else
                {
                    infoOneFileOpen.WorkingDirectory = strTmpCurrentPath;
                }
                infoOneFileOpen.FileName = strTmpCurrentFileName;
                infoOneFileOpen.Arguments = "";
                System.Diagnostics.Process.Start(infoOneFileOpen);
            }
            catch (Exception ex)
            {
                MessageBox.Show("你还没查出文件或者文件不存在！");
            }

        }

        private void 打开文件夹ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dgvData.Rows.Count > 0)
            {
                string strTmpCurrentPath = dgvData.CurrentRow.Cells[1].Value.ToString();
                string strTmpCurrentFileName = dgvData.CurrentRow.Cells[0].Value.ToString();
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName = "explorer";
                string strTmpCurrentFileFullPahth = strTmpCurrentPath + "\\" + strTmpCurrentFileName;
                proc.StartInfo.Arguments = @"/select," + strTmpCurrentFileFullPahth;
                //选中"notepad.exe"这个程序,即记事本，但不打开，只有双击的时候才打开
                proc.Start();
            }
        }

        private void 复制文件到桌面ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                string strTmpCurrentPath = dgvData.CurrentRow.Cells[1].Value.ToString();
                string strTmpCurrentFileName = dgvData.CurrentRow.Cells[0].Value.ToString();
                System.IO.File.Copy(strTmpCurrentPath + "\\" + strTmpCurrentFileName, Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" + strTmpCurrentFileName, true);
                MessageBox.Show("成功复制" + strTmpCurrentFileName + "到桌面");
            }
            catch (Exception ex)
            {
                MessageBox.Show("你还没查出文件呢！");
            }

        }

        private void 更新规格ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string _path = dgvData.CurrentRow.Cells[1].Value.ToString();
            string _filename = dgvData.CurrentRow.Cells[0].Value.ToString();
            if (PanduanSpec(dgvData.CurrentRow.Cells[0].Value.ToString(), dgvData.CurrentRow.Cells[1].Value.ToString()))
            {
                int i = _path.IndexOf("WaitTest");
                notifyIcon1.BalloonTipTitle = "文件不需更新";
                notifyIcon1.BalloonTipText = "C:\\" + _path.Substring(i + 9) + "\\" + _filename + "文件与服务器上的一致,无需更新";
                notifyIcon1.ShowBalloonTip(1000);
            }
            else
            {
                if (MessageBox.Show("服务器上的文件和本地的不一致或者本地无此文件，需要更新吗？", "确定：更新并打开本地文件   取消：不更新打开本地文件", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    UpdateSpec(_filename, _path);
                }
            }
        }

        private void btniLogOff_Click(object sender, EventArgs e)
        {
            WindowsFun.Winlogoff();
        }

        private void btniReboot_Click(object sender, EventArgs e)
        {
            WindowsFun.Winreboot();
        }

        private void btniShutDown_Click(object sender, EventArgs e)
        {
            WindowsFun.WinShutdown();
        }
        #endregion

        #endregion

        private void chkSpec_CheckedChanged(object sender, EventArgs e)
        {
            if (chkSpec.Checked)
            {
                SetControlVisible(false);
                //lblQueryDir.Text = textBox44.Text;
                comboBox4.Visible = true;
                label9.Visible = true;
                if (comboBox4.Text != "全部")
                {
                    checktype = comboBox4.Text;
                }
                else
                {
                    checktype = "";
                }
                comboBoxproduct3_SelectedIndexChanged(sender, e);
            }
            else
            {
                lblQueryDir.Text = "";
                if (cbFullDisk.Checked)
                {
                    SetControlVisible(true);
                }
                else
                {
                    SetControlVisible(false);
                }
            }
        }

        private void chkSrc_CheckedChanged(object sender, EventArgs e)
        {
            if (chkSrc.Checked)
            {
                SetControlVisible(false);
                //lblQueryDir.Text = textBox45.Text;
                comboBox4.Visible = false;
                label9.Visible = false;
                checktype = "";
                comboBoxproduct3_SelectedIndexChanged(sender, e);
            }
            else
            {
                lblQueryDir.Text = "";
                if (cbFullDisk.Checked)
                {
                    SetControlVisible(true);
                }
                else
                {
                    SetControlVisible(false);
                }
            }
        }

        private void ttxFileName_TextChanged(object sender, EventArgs e)
        {
            //if (dataGridView4.Visible)
            //{
            //    return;
            //}
            
            if (ttxFileName.Text != "")
            {
                //dataGridView4.Visible = true;
                string sql = "SELECT DISTINCT CI_CODE AS CI编号,CI_NAME AS CI名称 FROM dbo.CI";
                sql += " LEFT JOIN dbo.PRODUCT_GROUP";
                sql += " ON CI.PRODUCT_GROUP_ID=dbo.PRODUCT_GROUP.PRODUCT_GROUP_ID";
                sql += " WHERE (CI_NAME LIKE '%" + ttxFileName.Text + "%' OR LOWER(CI_CODE) LIKE '%'+LOWER('" + ttxFileName.Text + "')+'%')";
                sql += " AND PRODUCT_GROUP_CODE='" + comboBoxproduct3.Text + "'";
                SqlDataAdapter sda = new SqlDataAdapter(sql, conn);//创建一个SqlDataAdapter对象
                DataSet ds = new DataSet();				//创建一个DataSet对象
                sda.Fill(ds);				//使用SqlDataAdapter对象的Fill方法填充DataSet数据集;
                //dataGridView4.DataSource = ds.Tables[0];//设置dataGridView1控件的数据源
                frmci.tianChong(ds);
                if (!frmci.Visible)
                {
                    frmci.Show();
                    //frmci.TopMost=true;
                    frmci.Activate();
                    frmci.Focus();
                }
                if (frmci.WindowState == FormWindowState.Minimized)
                {
                    frmci.WindowState = FormWindowState.Normal;
                }
                //frmci.TopMost = true;
                frmci.Activate();
                frmci.Focus();
            }
            else
            {
                //dataGridView4.Visible = false;
                frmci.Hide();
            }
        }

        private void 回写文件名Double_Click(object sender, EventArgs e)
        {
            //try
            //{
            ttxFileName.Text = dataGridView4.CurrentRow.Cells[0].Value.ToString();
            btniQueryStart_Click(sender, e);
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show("你还没查出文件名呢！");
            //}
        }

        public void writeBack(string str, object sender, EventArgs e)
        {
            ttxFileName.Text = str;
            btniQueryEnd_Click(sender, e);
            btniQueryStart_Click(sender, e);

        }

        private void UpdateSpec(string filename, string path)
        {
            FileInfo fileInfo = null, b = null;
            if (path.Split(':').Length == 1)
            {
                fileInfo = new FileInfo(path + "\\" + filename);
                int i = path.IndexOf("WaitTest");
                b = new FileInfo("C:\\" + path.Substring(i + 9) + "\\" + filename);
            }
            else
            {
                fileInfo = new FileInfo("\\\\172.16.1.204\\WaitTest\\" + path.Split(':')[1] + "\\" + filename);
                b = new FileInfo(path + "\\" + filename);
            }

            if (b.Exists)
            {
                b.IsReadOnly = false;
            }
            if (!b.Directory.Exists)
            {
                b.Directory.Create();
            }
            System.IO.File.Copy(@fileInfo.FullName, @b.FullName, true);
            notifyIcon1.BalloonTipTitle = "文件更新";
            notifyIcon1.BalloonTipText = b.FullName + "文件已更新.";
            notifyIcon1.ShowBalloonTip(1000);
        }

        private bool PanduanSpec(string filename, string path)
        {
            bool bol = false;
            FileInfo a = null, b = null;
            if (path.Split(':').Length == 1)
            {
                a = new FileInfo(path + "\\" + filename);
                int i = path.IndexOf("WaitTest");
                b = new FileInfo("C:\\" + path.Substring(i + 9) + "\\" + filename);
                if (b.Exists)
                {
                    if (a.Length == b.Length)
                    {
                        bol = true;
                    }
                    else
                    {
                        bol = false;
                    }
                }
            }
            else
            {
                a = new FileInfo(path + "\\" + filename);
                b = new FileInfo("\\\\172.16.1.204\\WaitTest\\" + path.Split(':')[1] + "\\" + filename);
                if (b.Exists)
                {
                    if (a.Length == b.Length)
                    {
                        bol = true;
                    }
                    else
                    {
                        bol = false;
                    }
                }
                else
                {
                    if (a.Exists)
                    {
                        MessageBox.Show("服务器无此规格但本地有此规格，打开本地规格！");
                        bol = true;
                    }
                    else
                    {
                        MessageBox.Show("服务器和本地都无此规格！");
                    }
                }
            }
            return bol;
        }

        private void comboBoxproduct3_SelectedIndexChanged(object sender, EventArgs e)
        {
            string str="";
            try
            {
                string sql = "SELECT GET_FOLDER_LAST FROM dbo.PRODUCT_GROUP WHERE PRODUCT_GROUP_CODE='" + comboBoxproduct3.Text + "'";
                SqlCommand cmd = new SqlCommand(sql, conn);
                str = Convert.ToString(cmd.ExecuteScalar());
            }
            catch
            {
                
            }

            if (comboBoxproduct3.Text.ToString().Contains("20") | comboBoxproduct3.Text.ToString().Contains("2.0"))
            {
                if (chkSpec.Checked)
                {
                    lblQueryDir.Text = "\\\\" + textBox47.Text + "\\WaitTest\\DF_E10_2.0\\Spec" + str + "\\" + checktype;
                }
                else if (chkSrc.Checked)
                {
                    lblQueryDir.Text = "\\\\" + textBox47.Text + "\\WaitTest\\DF_E10_2.0\\WD_PR" + str + "\\" + checktype;
                }
                cimulu = "DF_E10_2.0";
            }
            else
            {
                if (chkSpec.Checked)
                {
                    lblQueryDir.Text = "\\\\" + textBox47.Text + "\\WaitTest\\DF_E10_1.1.1\\Spec" + str + "\\" + checktype;
                }
                else if (chkSrc.Checked)
                {
                    lblQueryDir.Text = "\\\\" + textBox47.Text + "\\WaitTest\\DF_E10_1.1.1\\WD_PR" + str + "\\" + checktype;
                }
                cimulu = "DF_E10_1.1.1";
            }
            if (comboBoxproduct3.Text.ToString().Contains("201") | comboBoxproduct3.Text.ToString().Contains("2.0.1"))
            {
                if (chkSpec.Checked)
                {
                    lblQueryDir.Text = "\\\\" + textBox47.Text + "\\WaitTest\\DF_E10_2.0.1\\Spec" + str + "\\" + checktype;
                }
                else if (chkSrc.Checked)
                {
                    lblQueryDir.Text = "\\\\" + textBox47.Text + "\\WaitTest\\DF_E10_2.0.1\\WD_PR" + str + "\\" + checktype;
                }
                cimulu = "DF_E10_2.0.1";
            }
            if (comboBoxproduct3.Text.ToString().Contains("202") | comboBoxproduct3.Text.ToString().Contains("2.0.2"))
            {
                if (chkSpec.Checked)
                {
                    lblQueryDir.Text = "\\\\" + textBox47.Text + "\\WaitTest\\DF_E10_2.0.2\\Spec" + str + "\\" + checktype;
                }
                else if (chkSrc.Checked)
                {
                    lblQueryDir.Text = "\\\\" + textBox47.Text + "\\WaitTest\\DF_E10_2.0.2\\WD_PR" + str + "\\" + checktype;
                }
                cimulu = "DF_E10_2.0.2";
            }
            if (comboBoxproduct3.Text.ToString().Contains("30") | comboBoxproduct3.Text.ToString().Contains("3.0"))
            {
                if (chkSpec.Checked)
                {
                    lblQueryDir.Text = "\\\\" + textBox47.Text + "\\WaitTest\\DF_E10_3.0\\Spec" + str + "\\" + checktype;
                }
                else if (chkSrc.Checked)
                {
                    lblQueryDir.Text = "\\\\" + textBox47.Text + "\\WaitTest\\DF_E10_3.0\\WD_PR" + str + "\\" + checktype;
                }
                cimulu = "DF_E10_3.0";
            }
            if (comboBoxproduct3.Text.ToString().Contains("301") | comboBoxproduct3.Text.ToString().Contains("3.0.1"))
            {
                if (chkSpec.Checked)
                {
                    lblQueryDir.Text = "\\\\" + textBox47.Text + "\\WaitTest\\DF_E10_3.0.1\\Spec" + str + "\\" + checktype;
                }
                else if (chkSrc.Checked)
                {
                    lblQueryDir.Text = "\\\\" + textBox47.Text + "\\WaitTest\\DF_E10_3.0.1\\WD_PR" + str + "\\" + checktype;
                }
                cimulu = "DF_E10_3.0.1";
            }
            if (comboBoxproduct3.Text=="CM_1.1")
            {
                if (chkSpec.Checked)
                {
                    lblQueryDir.Text = "\\\\" + textBox47.Text + "\\WaitTest\\DF_CM_1.1\\Spec" + str + "\\" + checktype;
                }
                else if (chkSrc.Checked)
                {
                    lblQueryDir.Text = "\\\\" + textBox47.Text + "\\WaitTest\\DF_CM_1.1\\WD_PR" + str + "\\" + checktype;
                }
                cimulu = "DF_CM_1.1";
            }
            if (comboBoxproduct3.Text == "DS_1.0")
            {
                if (chkSpec.Checked)
                {
                    lblQueryDir.Text = "\\\\" + textBox47.Text + "\\WaitTest\\DF_DS_1.0\\Spec" + str + "\\" + checktype;
                }
                else if (chkSrc.Checked)
                {
                    lblQueryDir.Text = "\\\\" + textBox47.Text + "\\WaitTest\\DF_DS_1.0\\WD_PR" + str + "\\" + checktype;
                }
                cimulu = "DF_DS_1.0";
            }
        }

        /// <summary>
        /// 规格查询text控件按回车执行查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ttxFileName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                ttxFileName_TextChanged(sender, e);

            }
        }

        public void findSpec(string str, object sender, EventArgs e)
        {
            string sql="SELECT "; 
                   sql+="CASE A.CI_FOLDER "; 
                   sql+="WHEN '' ";
                   sql+= "THEN '\\\\'+'" + textBox47.Text + "'+'\\'+'" + "WaitTest" + "'+'\\'+'"+ cimulu  + "'+B.GET_FOLDER_FRONT + B.CI_FOLDER + ';' + CI_CODE ";
                   sql+="+ '.' + EXTENSION_NAME ";
                   sql+="ELSE ";
                   sql+= "'\\\\'+'" + textBox47.Text + "'+'\\'+'" + "WaitTest" + "'+'\\'+'" + cimulu + "'+B.GET_FOLDER_FRONT + B.CI_FOLDER + '\\' + A.CI_FOLDER + ';' + CI_CODE ";
                   sql+="+ '.' + EXTENSION_NAME ";
                   sql+="END ";
                   sql+="AS PATH ";
                   sql+="FROM    dbo.CI A ";
                   sql+="LEFT JOIN dbo.CI_TYPE B ON A.CI_TYPE_ID = B.CI_TYPE_ID ";
                   sql+= "LEFT JOIN PRODUCT_GROUP C ON A.PRODUCT_GROUP_ID=C.PRODUCT_GROUP_ID ";
                   sql+="WHERE   CI_CODE = '"+ str +"' AND B.GET_FOLDER_FRONT='\\Spec' AND C.PRODUCT_GROUP_CODE='"+comboBoxproduct3.Text+"'";
            SqlCommand cmd = new SqlCommand(sql, conn);
            string str1 = Convert.ToString(cmd.ExecuteScalar());
            try
            {
                string _path = str1.Split(';')[0];
                string _filename = str1.Split(';')[1];
                if (PanduanSpec(_filename,_path))
                {
                    int i = _path.IndexOf("WaitTest");
                    notifyIcon1.BalloonTipTitle = "文件不需更新";
                    notifyIcon1.BalloonTipText = "C:\\" + _path.Substring(i + 9) + "\\" + _filename + "文件与服务器上的一致,无需更新";
                    notifyIcon1.ShowBalloonTip(1000);
                }
                else
                {
                    if (MessageBox.Show("服务器上的文件和本地的不一致或者本地无此文件，需要更新吗？", "确定：更新并打开本地文件   取消：不更新打开本地文件", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    {
                        UpdateSpec(_filename, _path);
                    }
                }
                System.Diagnostics.Process pOneFile = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo infoOneFileOpen = new System.Diagnostics.ProcessStartInfo();
                if (_path.Split(':').Length == 1)
                {
                    int i = _path.IndexOf("WaitTest");
                    infoOneFileOpen.WorkingDirectory = "C:\\" + _path.Substring(i + 9) + "\\";
                }
                else
                {
                    infoOneFileOpen.WorkingDirectory = _path;
                }
                infoOneFileOpen.FileName = _filename;
                infoOneFileOpen.Arguments = "";
                System.Diagnostics.Process.Start(infoOneFileOpen);
            }
            catch (Exception ex)
            {
                MessageBox.Show("你还没查出文件或者文件不存在！");
            }

        }

       

        public void button85_Click_1(object sender, EventArgs e) //另存为环境
        {
            if (frmconfirm.Visible)
            {
                return;
            }
            else
            {
                AppareForm();
            }

        }

        private void button22_Click(object sender, EventArgs e) //环境信息
        {
            if (splitContainer2.Panel1Collapsed)
            {
                splitContainer2.Panel1Collapsed = false;
            }
            else
            {
                splitContainer2.Panel1Collapsed = true;
            }
        }

        private void RecursionTreeControl(XmlNode xmlNode, TreeNodeCollection nodes, string text)
        {
            foreach (XmlNode node in xmlNode.ChildNodes)//循环遍历当前元素的子元素集合
            {
                TreeNode new_child = new TreeNode();//定义一个MyTreeNode节点对象  
                //new_child.Id = node.Attributes["Id"].Value;
                new_child.Name = node.Attributes["Name"].Value;
                new_child.Text = node.Attributes["Text"].Value;
                //new_child.Ip1 = node.Attributes["Ip1"].Value;
                //new_child.Db_name1 = node.Attributes["Db_name1"].Value;
                //new_child.Account1 = node.Attributes["Account1"].Value;
                //new_child.Password1 = node.Attributes["Password1"].Value;
                //new_child.Ip1 = node.Attributes["Ip2"].Value;
                //new_child.Db_name1 = node.Attributes["Db_name2"].Value;
                //new_child.Account1 = node.Attributes["Account2"].Value;
                //new_child.Password1 = node.Attributes["Password2"].Value;
                //new_child.Ip1 = node.Attributes["Ip3"].Value;
                //new_child.Db_name1 = node.Attributes["Db_name3"].Value;
                //new_child.Account1 = node.Attributes["Account3"].Value;
                //new_child.Password1 = node.Attributes["Password3"].Value;
                //new_child.version = node.Attributes["version"].Value;
                if (new_child.Name.Contains("Root"))
                {
                    new_child.ImageIndex = 3;
                    new_child.SelectedImageIndex = 3;
                }
                else
                {
                    new_child.ImageIndex = 8;
                    new_child.SelectedImageIndex = 4;
                }
                if (new_child.Name == text)
                {
                    Trv_Config.SelectedNode = new_child;
                }
                nodes.Add(new_child);//向当前TreeNodeCollection集合中添加当前节点
                RecursionTreeControl(node, new_child.Nodes, text);//调用本方法进行递归
            }
        }
        //双击时修改
        private void Trv_Config_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point ClickPoint = new Point(e.X, e.Y);
                TreeNode CurrentNode = (TreeNode)Trv_Config.GetNodeAt(ClickPoint);
                if (CurrentNode != null)//判断你点的是不是一个节点
                {
                    Trv_Config.SelectedNode = CurrentNode;//选中这个节点
                    Trv_Config.LabelEdit = true;
                    Trv_Config.SelectedNode.BeginEdit();

                }
            }
        }

        ////递归遍历节点内容,最关键的函数
        //private void parseNode(TreeNode tn, StringBuilder sb)
        //{
        //    IEnumerator ie = tn.Nodes.GetEnumerator();

        //    while (ie.MoveNext())
        //    {
        //        TreeNode ctn = (TreeNode)ie.Current;
        //        xmlLine = GetRSSText(ctn);
        //        sb.Append(xmlLine);
        //        //如果还有子节点则继续遍历
        //        if (ctn.Nodes.Count > 0)
        //        {
        //            parseNode(ctn, sb);
        //        }
        //        sb.Append("</Node>");
        //    }


        //}
        //成生RSS节点的XML文本行
        //private string GetRSSText(TreeNode node)
        //{
        //    //根据Node属性生成XML文本
        //    //string rssText = "<Node Id=\"" + node.Id + "\" Name=\"" + node.Name + "\" Text=\"" + node.Text + "\" Ip1=\"" + node.Ip1 + "\" Db_name1=\"" + node.Db_name1 + "\" Account1=\"" + node.Account1 + "\" Password1=\"" + node.Password1 + "\" >";
        //    string rssText = "<Node Name=\"" + node.Name + "\" Text=\"" + node.Text + "\" >";
        //    return rssText;
        //}

        //添加子节点
        //private void addTreeNode_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        TreeNode CurrentNode = Trv_Config.SelectedNode;
        //        XmlDocument xmlDoc;
        //        XmlNode xmlnode;
        //        XmlNodeList nodeList;
        //        XmlElement xmlelem;
        //        xmlDoc = new XmlDocument();
        //        xmlDoc.Load("TreeXml.xml");
        //        XmlNode xd = xmlDoc.SelectSingleNode("//Root[@Name='" + CurrentNode.Name + "']");
        //        xmlelem = xmlDoc.CreateElement("Node");
        //        xmlelem.SetAttribute("Name", DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.ToString("HHmmss"));
        //        xmlelem.SetAttribute("Text", "新建子节点");
        //        xmlelem.SetAttribute("IP", "127.0.0.1");
        //        xd.AppendChild(xmlelem);
        //        xmlDoc.Save("TreeXml.xml");
        //        Trv_Config.SelectedNode.Nodes.Add("新建子节点");
        //        toolStripStatusLabel1.Text = "新建子节点";
        //    }
        //    catch (Exception ex)
        //    {
        //        toolStripStatusLabel1.Text = ex.Message;
        //    }
        //}
        //删除节点
        private void deleteTreeNode_Click(object sender, EventArgs e)
        {
            try
            {
                TreeNode CurrentNode = Trv_Config.SelectedNode;
                doc.Load("TreeXml.xml");
                XmlNode xd = doc.SelectSingleNode("//*[@Name='" + CurrentNode.Name + "']");
                XmlElement xe = (XmlElement)xd;
                xe.ParentNode.RemoveChild(xe);
                doc.Save("TreeXml.xml");
                Trv_Config.SelectedNode.Remove();
            }
            catch (Exception ex)
            {

                toolStripStatusLabel1.Text = ex.Message;
            }
        }

        private void addRootTreeNode_Click(object sender, EventArgs e)
        {
            //try
            //{
            //Trv_Config.Nodes.Add("新建根节点");
            //toolStripStatusLabel1.Text = "新建根节点成功";
            //}
            //catch (Exception ex)
            //{
            //    toolStripStatusLabel1.Text = ex.Message;
            //}
            if (frmconfirm.Visible)
            {
                return;
            }
            else
            {
                frmconfirm.btn_Comfirm.Visible = true;
                frmconfirm.btn_Cancel.Visible = true;
                frmconfirm.comboBox1.Visible = false;
                frmconfirm.label2.Visible = false;
                frmconfirm.Show();
                frmconfirm.textBox1.Focus();
                frmconfirm.TopMost = true;
            }

        }
        //保存
        //private void SaveXml_Click(object sender, EventArgs e)
        //{
        //try
        //{

        //    //写文件头部内容
        //    //下面是生成RSS的OPML文件
        //    sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        //    sb.Append("<Tree>");

        //    //遍历根节点
        //    foreach (TreeNode node in Trv_Config.Nodes)
        //    {
        //        xmlLine = GetRSSText((TreeNode)node);
        //        sb.Append(xmlLine);

        //        //递归遍历节点
        //        parseNode(node, sb);

        //        sb.Append("</Node>");
        //    }
        //    sb.Append("</Tree>");

        //    StreamWriter sr = new StreamWriter("TreeXml.xml", false, System.Text.Encoding.UTF8);
        //    sr.Write(sb.ToString());
        //    sr.Close();
        //    toolStripStatusLabel1.Text = "保存成功";
        //}
        //catch (Exception ex)
        //{
        //    toolStripStatusLabel1.Text = ex.Message;
        //}

        //}

        private void Trv_Config_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            if (e.Label == null)    //调试专用
            {
                return;
                MessageBox.Show("P1在这");
            }
            TreeNode CurrentNode = Trv_Config.SelectedNode;
            doc.Load("TreeXml.xml");
            XmlNode xd = doc.SelectSingleNode("//*[@Name='" + CurrentNode.Name + "']");
            XmlElement xe = (XmlElement)xd;
            xe.SetAttribute("Text", e.Label);
            doc.Save("TreeXml.xml");
        }

        private void 全部展开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Trv_Config.ExpandAll();
        }

        private void 全部收起ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Trv_Config.CollapseAll();
        }

        public void AppareForm()
        {
            frmconfirm.comboBox1.Items.Clear();

            foreach (TreeNode tn in Trv_Config.Nodes)
            {
                frmconfirm.comboBox1.Items.Add(tn.Text);
                Listtree.Add(tn.Name);

            }
            if (frmconfirm.comboBox1.Items.Count > 0)
            {
                frmconfirm.comboBox1.Text = frmconfirm.comboBox1.Items[0].ToString();
                frmconfirm.textBox2.Text = Listtree[0].ToString();
            }
            frmconfirm.label2.Visible = true;
            frmconfirm.comboBox1.Visible = true;
            frmconfirm.btn_Confirm1.Visible = true;
            frmconfirm.btn_Cancel1.Visible = true;
            frmconfirm.Show();
            frmconfirm.textBox1.Focus();
            frmconfirm.TopMost = true;
        }

        public string[] GetDate()
        {
            string[] dt = new string[17];
            dt[0] = comboBox6.Text;
            dt[16] = "";
            int j = 1;
            for (int i = 0; i < 3; i++)
            {
                dt[j] = ((string)dataGridView3.Rows[i].Cells[0].Value == null) ? "" : (string)dataGridView3.Rows[i].Cells[0].Value;
                dt[j + 1] = ((string)dataGridView3.Rows[i].Cells[1].Value == null) ? "" : (string)dataGridView3.Rows[i].Cells[1].Value;
                dt[j + 2] = ((string)dataGridView3.Rows[i].Cells[2].Value == null) ? "" : (string)dataGridView3.Rows[i].Cells[2].Value;
                dt[j + 3] = ((string)dataGridView3.Rows[i].Cells[3].Value == null) ? "" : (string)dataGridView3.Rows[i].Cells[3].Value;
                dt[j + 4] = ((string)dataGridView3.Rows[i].Cells[4].Value == null) ? "" : (string)dataGridView3.Rows[i].Cells[4].Value;
                j = j + 5;
            }
            return dt;
        }

        private void Trv_Config_AfterSelect(object sender, TreeViewEventArgs e)
        {
            //if (e.Action == TreeViewAction.Unknown)
            //{
            //    return;
            //}
            TreeNode CurrentNode = Trv_Config.SelectedNode;
            if (CurrentNode.Name == "Root19000101000000" | CurrentNode.Name == "Root19000101000001")
            {
                deleteTreeNode.Enabled = false;
            }
            else
            {
                deleteTreeNode.Enabled = true;
            }

            if (!CurrentNode.Name.Contains("Root"))
            {
                doc.Load("TreeXml.xml");
                XmlNode xd = doc.SelectSingleNode("//*[@Name='" + CurrentNode.Name + "']");
                XmlElement xe = (XmlElement)xd;

                try
                {
                    comboBoxproduct2.Text = xe.Attributes[18].Value;
                    comboBoxConfig.Text = xe.Attributes[19].Value;
                    comboBoxproduct1.Text = xe.Attributes[18].Value;
                    comboBoxproduct3.Text = xe.Attributes[18].Value;
                    comboBox6.Text = xe.Attributes[2].Value;
                }
                catch (Exception ex)
                {
                    comboBoxproduct2.Text = "";
                    comboBoxConfig.Text = "";
                }
                int j = 3;
                for (int i = 0; i < 3; i++)
                {
                    dataGridView3.Rows[i].Cells[0].Value = xe.Attributes[j].Value;
                    dataGridView3.Rows[i].Cells[1].Value = xe.Attributes[j + 1].Value;
                    dataGridView3.Rows[i].Cells[2].Value = xe.Attributes[j + 2].Value;
                    dataGridView3.Rows[i].Cells[3].Value = xe.Attributes[j + 3].Value;
                    dataGridView3.Rows[i].Cells[4].Value = xe.Attributes[j + 4].Value;
                    j = j + 5;
                }
                SaveConfig();
            }
            //if (System.IO.File.Exists(str))											//判断是否存在INI文件
            //{
            //    WritePrivateProfileString(strOne, "Node", CurrentNode.Name, str);
            //}
            //else
            //{
            //    MessageBox.Show("对不起，你所要修改的INI文件不存在，请确认后再进行修改操作！", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
            doc.Load("DefaultData.xml");
            XmlNode nd = doc.SelectSingleNode("//Node");
            nd.InnerText = CurrentNode.Name;
            doc.Save("DefaultData.xml");
        }

        public void Save_Environment()  //保存环境方法
        {
            if (frmconfirm.Visible)
            {
                return;
            }
            TreeNode currentnode = Trv_Config.SelectedNode;
            if (currentnode == null || currentnode.Name.Contains("Root"))
            {
                //MessageBox.Show("请先选择要保存的节点或点另存环境按钮！");
                AppareForm();
                return;
            }
            string[] dt = GetDate();
            TreeNode CurrentNode = Trv_Config.SelectedNode;
            //string name = "Node" + DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.ToString("HHmmss");
            doc.Load("TreeXml.xml");
            XmlNode xd = doc.SelectSingleNode("//*[@Name='" + CurrentNode.Name + "']");
            XmlElement xe = (XmlElement)xd;
            xe.SetAttribute("Name", CurrentNode.Name);
            xe.SetAttribute("Text", CurrentNode.Text);
            if (CurrentNode.Text == null)    //调试专用
            {
                MessageBox.Show("P2在这");
            }
            xe.SetAttribute("Mulu", dt[0]);
            xe.SetAttribute("IP", dt[1]);
            xe.SetAttribute("DbName", dt[2]);
            xe.SetAttribute("Account", dt[3]);
            xe.SetAttribute("Password", dt[4]);
            xe.SetAttribute("BootType", dt[5]);
            xe.SetAttribute("IP1", dt[6]);
            xe.SetAttribute("DbName1", dt[7]);
            xe.SetAttribute("Account1", dt[8]);
            xe.SetAttribute("Password1", dt[9]);
            xe.SetAttribute("BootType1", dt[10]);
            xe.SetAttribute("IP2", dt[11]);
            xe.SetAttribute("DbName2", dt[12]);
            xe.SetAttribute("Account2", dt[13]);
            xe.SetAttribute("Password2", dt[14]);
            xe.SetAttribute("BootType2", dt[15]);
            xe.SetAttribute("Version", comboBoxproduct2.Text);
            xe.SetAttribute("E_Info", comboBoxConfig.Text);
            doc.Save("TreeXml.xml");
            toolStripStatusLabel1.Text = "保存节点成功";
            MessageBox.Show("保存成功");

        }

        private void checkBox7_CheckedChanged(object sender, EventArgs e)//CM启动参数状态
        {
            doc.Load("DefaultData.xml");
            XmlNode nd = doc.SelectSingleNode("//CM_Check");
            if (checkBox7.Checked)
            {
                //WritePrivateProfileString(strOne, "CM_Check", "true", str);
                nd.InnerText = "true";
            }
            else
            {
                //WritePrivateProfileString(strOne, "CM_Check", "false", str);
                nd.InnerText = "false";
            }
            doc.Save("DefaultData.xml");

        }

        private void checkBox8_CheckedChanged(object sender, EventArgs e)
        {
            doc.Load("DefaultData.xml");
            XmlNode nd = doc.SelectSingleNode("//Client_L");

            if (checkBox8.Checked)
            {
                //WritePrivateProfileString(strOne, "Client_L", "true", str);
                nd.InnerText = "true";
            }
            else
            {
                //WritePrivateProfileString(strOne, "Client_L", "false", str);
                nd.InnerText = "false";
            }
            doc.Save("DefaultData.xml");
        }

        private void checkBox10_CheckedChanged(object sender, EventArgs e)
        {
            doc.Load("DefaultData.xml");
            XmlNode nd = doc.SelectSingleNode("//Client_d");
            if (checkBox10.Checked)
            {
                //WritePrivateProfileString(strOne, "Client_d", "true", str);
                nd.InnerText = "true";
            }
            else
            {
                //WritePrivateProfileString(strOne, "Client_d", "false", str);
                nd.InnerText = "false";
            }
            doc.Save("DefaultData.xml");
        }

        private void Trv_Config_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                Trv_Config.SelectedNode = Trv_Config.GetNodeAt(e.X, e.Y);
                StartServer.Enabled = button5.Enabled;
            }
        }

        private void button6_Click(object sender, EventArgs e) //打开提取文件夹
        {
            if (Directory.Exists(textBox6.Text + "\\平台文件"))
            {
                Process.Start(textBox6.Text + "\\平台文件");
            }
        }

        private void dataGridView3_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {

                SaveConfig();
        }

        private void comboBox12_SelectedValueChanged(object sender, EventArgs e)
        {
            doc.Load("DefaultData.xml");
            XmlNode nd = doc.SelectSingleNode("//Doc_Type");
            nd.InnerText = comboBox12.Text;
            doc.Save("DefaultData.xml");
        }


        //private void btnDel_Click(object sender, EventArgs e)
        //{
        //    for (int i = 0; i < Shortcutdgv.Rows.Count; i++)//遍历行集合
        //    {
        //        if (Shortcutdgv.Rows[i].Cells[0].Value != null &&
        //            Shortcutdgv.Rows[i].Cells[1].Value != null &&
        //            Shortcutdgv.Rows[i].Cells[2].Value != null)//判断值是否为空
        //        {
        //            if (Convert.ToBoolean(Shortcutdgv.Rows[i].Cells[0].Value.ToString()))//判断是否选中项
        //            {
        //                P_Shortcut.RemoveAll(//标记集合中指定项
        //                    (pp) =>
        //                    {
        //                        if (pp.Name == Shortcutdgv.Rows[i].Cells[1].Value.ToString() &&
        //                            pp.Path == Shortcutdgv.Rows[i].Cells[2].Value.ToString())
        //                            pp.ft = true;//开始标识
        //                        return false;//不删除项
        //                    });
        //            }
        //        }
        //    }
        //    P_Shortcut.RemoveAll(//删除集合中指定项
        //        (pp) =>
        //        {
        //            return pp.ft;
        //        });
        //}

        private void ShortCutAddButton_Click(object sender, EventArgs e)
        {
            Shortcut sc = new Shortcut();
            sc.PropertyChanged += sc_PropertyChanged;
            sc.Seq = shortcutseq;
            sc.Name = "";
            sc.Path = "";
            P_Shortcut.Add(sc);
            Button bt = new Button();
            bt.Name = shortcutseq.ToString();
            bt.Text = "";
            P_Button.Add(bt);
            flowLayoutPanel2.Controls.Add(bt);
            bt.Click += bt_Click;
            ShortcutSave(sc);
            this.ShortcutGrid.RefreshDataSource();
            shortcutseq++;
        }

        void sc_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Name")
            {
                doc.Load("ShortCut.XML");
                for (int i = 0; i < P_Shortcut.Count; i++)
                {
                    P_Button[i].Text = P_Shortcut[i].Name;
                    XmlNode xd = doc.SelectSingleNode("//*[@Seq='" + P_Shortcut[i].Seq + "']");
                    XmlElement xe = (XmlElement)xd;
                    xe.SetAttribute("Name", P_Shortcut[i].Name);
                    doc.Save("ShortCut.XML");
                }

            }
            if (e.PropertyName == "Path")
            {
                doc.Load("ShortCut.XML");
                for (int i = 0; i < P_Shortcut.Count; i++)
                {
                    XmlNode xd = doc.SelectSingleNode("//*[@Seq='" + P_Shortcut[i].Seq + "']");
                    XmlElement xe = (XmlElement)xd;
                    xe.SetAttribute("Path", P_Shortcut[i].Path);
                    doc.Save("ShortCut.XML");
                }
            }
        }

        void bt_Click(object sender, EventArgs e)
        {
            try
            {
                Button bt = (Button)sender;
                for (int i = 0; i < P_Shortcut.Count; i++)
                {
                    if(P_Shortcut[i].Seq.ToString()==bt.Name)
                    {
                        Process.Start(P_Shortcut[i].Path);
                    }
                }
            }
            catch
            {
                
            }

        }

        private void ShotcutDelButton_Click(object sender, EventArgs e)
        {
            //for (int i = 0; i < ShortcutGrid.FocusedView.RowCount; i++)//遍历行集合
            //{

            //    if (Convert.ToBoolean(ShortcutGrid.FocusedView.  Rows[i].Cells[0].Value.ToString()))//判断是否选中项
            //        {
            //            P_Shortcut.RemoveAll(//标记集合中指定项
            //                (pp) =>
            //                {
            //                    if (pp.Name == dgv_Message.Rows[i].Cells[1].Value.ToString() &&
            //                        pp.Path == Convert.ToSingle(dgv_Message.Rows[i].Cells[2].Value.ToString()))
            //                        pp.ft = true;//开始标识
            //                    return false;//不删除项
            //                });
            //        }
                
            //}
            //P_Fruit.RemoveAll(//删除集合中指定项
            //    (pp) =>
            //    {
            //        return pp.ft;
            //    });
            for (int j = 0; j < MainBindingSource.Count; j++)
            {
                Shortcut sc = MainBindingSource[j] as Shortcut;
                //MessageBox.Show(sc.Seq.ToString());
                if (sc != null && sc.ft == true)
                {
                    //P_Shortcut.RemoveAt(sc.Seq);

                    for (int i = 0; i < P_Button.Count; i++)
                    {
                        if (P_Button[i].Name == sc.Seq.ToString())
                        {
                            flowLayoutPanel2.Controls.Remove(P_Button[i]);
                            P_Button.Remove(P_Button[i]);
                            ShortcutDel(sc);
                        }
                    }
                    this.MainBindingSource.RemoveAt(j);
                    j--;
                }
            }
        }

        private void ShotcutPathButtonEdit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            openFileDialog1.FileName = ShortcutGrid.FocusedView.ActiveEditor.EditValue.ToString();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                ShortcutGrid.FocusedView.ActiveEditor.EditValue = openFileDialog1.FileName;
            }
        }

        private void ShortcutSave(Shortcut sc)
        {
            doc.Load("ShortCut.XML");
            XmlNode root = doc.SelectSingleNode("ShortCut");
            XmlElement xmlelem = doc.CreateElement("Button");
            xmlelem.SetAttribute("Seq", sc.Seq.ToString());
            xmlelem.SetAttribute("Name", sc.Name);
            xmlelem.SetAttribute("Path", sc.Path);
            xmlelem.SetAttribute("ft", sc.ft.ToString());
            root.AppendChild(xmlelem);
            doc.Save("ShortCut.XML");
        }

        private void ShortcutDel(Shortcut sc)
        {
            doc.Load("ShortCut.XML");
            XmlNode xd = doc.SelectSingleNode("//*[@Seq='" + sc.Seq + "']");
            XmlElement xe = (XmlElement)xd;
            xe.ParentNode.RemoveChild(xe);
            doc.Save("ShortCut.XML");
        }

        private void LoadShortcut()
        {
            doc.Load("ShortCut.XML");
            XmlNode root = doc.SelectSingleNode("ShortCut");
            for (int i = 0; i < root.ChildNodes.Count; i++)
            {
                Shortcut sc = new Shortcut();
                sc.PropertyChanged += sc_PropertyChanged;
                sc.Seq = Convert.ToInt32(root.ChildNodes[i].Attributes[0].Value);
                sc.Name = root.ChildNodes[i].Attributes[1].Value;
                sc.Path = root.ChildNodes[i].Attributes[2].Value;
                sc.ft = Convert.ToBoolean(root.ChildNodes[i].Attributes[3].Value);
                P_Shortcut.Add(sc);
                Button bt = new Button();
                bt.Name = root.ChildNodes[i].Attributes[0].Value;
                bt.Text = root.ChildNodes[i].Attributes[1].Value;
                bt.Click += bt_Click;
                P_Button.Add(bt);
                flowLayoutPanel2.Controls.Add(bt);
            }
        }
   
        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e) //规格查询类型
        {
            if (comboBox4.Text != "全部")
            {
                checktype = comboBox4.Text; 
            }
            else
            {
                checktype = ""; 
            }
            comboBoxproduct3_SelectedIndexChanged(sender, e);
        }

        private void btnManual_Click(object sender, EventArgs e)
        {
            string time= textBox42.Text;
            textBox42.Text = DateTime.Parse(DateTime.Now.ToString("HH:mm:ss")).ToString();
            string cmd = "d:\\windows\\system32\\net.exe stop digiwin.E10.APService";
            Execute(cmd, 0);
            cmd = "d:\\windows\\system32\\net.exe stop digiwin.E10.DeploymentService";
            Execute(cmd, 0);
            cmd = "d:\\windows\\system32\\iisreset.exe /stop";
            Execute(cmd, 0);
            updateE10(time);
        }

        private void 生成结案文本ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string sql = "SELECT DISTINCT SUBSTRING(E.PRODUCT_GROUP_CODE,1,9) FROM dbo.ISSUE A LEFT JOIN dbo.ISSUE_D3 B ON A.ISSUE_ID=B.ISSUE_ID LEFT JOIN dbo.PRODUCT_GROUP E ON B.PRODUCT_GROUP_ID=E.PRODUCT_GROUP_ID LEFT JOIN dbo.SINGLE_PATCH_LOG_D C ON B.APPLY_CI_ID=C.APPLY_CI_ID LEFT JOIN dbo.SINGLE_PATCH_LOG D ON C.SINGLE_PATCH_LOG_ID=D.SINGLE_PATCH_LOG_ID WHERE A.DOC_NO='"+ dataGridView1.CurrentRow.Cells[3].Value + "' AND B.TASK_TYPE IN ('2','3') AND B.PROCESS_STATUS='4' AND B.PROCESS_CLOSED=1";
            string sql1 = "SELECT D.TYPEKEY+'.'+D.CURRENT_VERSION+'.'+RTRIM(LTRIM(STR(D.SEQUENCE_NO))),A.DOC_NO FROM dbo.ISSUE A LEFT JOIN dbo.ISSUE_D3 B ON A.ISSUE_ID=B.ISSUE_ID LEFT JOIN dbo.SINGLE_PATCH_LOG_D C ON B.APPLY_CI_ID=C.APPLY_CI_ID LEFT JOIN dbo.SINGLE_PATCH_LOG D ON C.SINGLE_PATCH_LOG_ID=D.SINGLE_PATCH_LOG_ID WHERE A.DOC_NO='" + dataGridView1.CurrentRow.Cells[3].Value + "' AND B.TASK_TYPE IN ('2','3') AND B.PROCESS_STATUS='4' AND B.PROCESS_CLOSED=1 AND D.SINGLE_PATCH_LOG_ID is not NULL";
            string msg="程序修改完成(";
            int i = 0;
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataReader sdr = cmd.ExecuteReader();
            
            if (sdr.HasRows)
            {
                while (sdr.Read())
                {
                    if (i!=0)
                    {
                        msg = msg + "\\";
                    }
                    msg += sdr[0];

                    i += 1;
                } 
            }
            msg = msg + "),请更新单支PATCH：";
            sdr.Close();

            SqlCommand cmd1 = new SqlCommand(sql1, conn);
            SqlDataReader sdr1 = cmd1.ExecuteReader();
            i = 0;
            if (sdr1.HasRows)
            {

                while (sdr1.Read())
                {
                    if (i != 0)
                    {
                        msg = msg + "、";
                    }
                    msg += sdr1[0];

                    i += 1;
                }
                msg += "。";
            }
            else
            {
                MessageBox.Show("没有包版记录或者包版未成功或者是公共服务！");
                msg += "公共服务没有单支PATCH，如需更新请联系服务组。";
                
            }
            sdr1.Close();
            Clipboard.SetText(msg);
        }

        private void comboBox16_DropDown(object sender, EventArgs e)
        {
            comboBox16.Items.Clear();
            if (comboBox15.Text != "")
            {
                string str1 = "Data Source=" + comboBox15.Text + ";database=master;Uid=" + dataGridView3.Rows[0].Cells[2].Value + ";Pwd=" + dataGridView3.Rows[0].Cells[3].Value + ";";
                DataTable myTable = getTable(str1, "select name from sysdatabases", "sysdatabases");
                for (int i = 0; i < myTable.Rows.Count; i++)
                {
                    comboBox16.Items.Add(myTable.Rows[i]["name"].ToString());
                }

            }
        }

        private void button28_Click(object sender, EventArgs e)
        {
            //copyDirectory(textBox53.Text, textBox25.Text);
            System.IO.File.Copy(@textBox53.Text, textBox25.Text + "\\Customization\\BusinessObjects\\ISSUE\\FormulaContainer.dcxml", true);
        }

        private void btnRun_Click(object sender, EventArgs e)
        {
            if (timer2.Enabled)
            {
                 timer2.Enabled = false;
            btnRun.Text = "运行";
            label69.Visible = false;
            }
            else
            {
                timer2.Enabled = true;
                btnRun.Text = "停止";
                
            }
            
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            label69.Text = DateTime.Now.ToLongTimeString();
            label69.Visible = true;
            if (label69.Text == textBox40.Text || label69.Text == textBox41.Text || label69.Text == textBox43.Text)
            {
                string time= textBox42.Text;
                textBox42.Text = DateTime.Parse(DateTime.Now.ToString("HH:mm:ss")).ToString();
                string cmd = "d:\\windows\\system32\\net.exe stop digiwin.E10.APService";
                Execute(cmd, 0);
                cmd = "d:\\windows\\system32\\net.exe stop digiwin.E10.DeploymentService";
                Execute(cmd, 0);
                cmd = "d:\\windows\\system32\\iisreset.exe /stop";
                Execute(cmd, 0);
                updateE10(time);
            } 
        }

        private void updateE10(string time)
        {
            //string sql = "SELECT  HOTFIX_TIME , ";
            //sql += "             B.DOC_NO ";
            //sql += "             FROM    dbo.ISSUE_D3 A ";
            //sql += "            LEFT JOIN dbo.APPLY_CI B ON A.APPLY_CI_ID = B.APPLY_CI_ID ";
            //sql += "    WHERE   HOTFIX_TIME >= '"+textBox42.Text"' ";
         
            //SqlCommand cmd = new SqlCommand(sql, conn);
            //SqlDataReader sdr = cmd.ExecuteReader();
            //string zuomianmulu = DateTime.Now.ToString("yyyy-MM-dd") + "—" + DateTime.Now.ToString("HH-mm-ss") + "—" + comboBoxproduct1.Text;
            //if (sdr.HasRows)
            //{
            //    string message = "", messagefinal = "", mulu = "", files = "";
            //    DirectoryInfo dinfo = null;
            //    dinfo = new DirectoryInfo(@"\\172.16.1.204\Deploy_temp_BAK\" + comboBoxproduct1.Text);

               
            //    while (sdr.Read())
            //    {

            //                files = sdr[1].ToString();
            //                message = sdr[1].ToString() + "____" + sdr[1].ToString() + "；";

            //        if (checkBox5.Checked)
            //        {
            //            mulu = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            //            copyDirectory(dinfo + "\\" + files, mulu + "\\一键提取文件" + zuomianmulu);
            //        }
            //        if (checkBox6.Checked)
            //        {
            //            mulu = comboBox6.Text;
            //            copyDirectory(dinfo + "\\" + files, mulu);
            //        }
            //        if (mulu == "")
            //        {
            //            MessageBox.Show("请选择你需要提取到的路径。");
            //            return;
            //        }
            //        messagefinal += message;
            //    }
            //    messagefinal += "\r\n已成功更新。";
            //    MessageBox.Show(messagefinal);
            //    sdr.Close();
            //}
            //else
            //{
            //    MessageBox.Show("检查一下版本，此版本没有你要提取的签出入单！");
            //    sdr.Close();
            //    return;
            //}
            string message = "", messagefinal = "", mulu = "", files = "",docno="";
            DirectoryInfo dinfo = null;
            dinfo = new DirectoryInfo(@"\\172.16.1.204\Deploy_temp_BAK\" + comboBoxproduct1.Text);
             FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos();
             List<FileSystemInfo> fsinfos1=new List<FileSystemInfo>();
             FileSystemInfo temp;
            comboBox11.Items.Clear();
            if (time == "")
            {
                return;
            }
            foreach (FileSystemInfo fsinfo in fsinfos)
            {
                if (fsinfo.LastWriteTime > Convert.ToDateTime(time))
                {
                    fsinfos1.Add(fsinfo);
                }
            }
            bool flag = true;
            for (int i = fsinfos1.Count - 1; i >= 0 && flag; i--)
            {
                flag = false;                                    //改进就在这里，当不再比较的时候flag就不会设置为true，停止排序
                for (int j = 0; j < i; j++)
                {

                    if (fsinfos1[j].LastWriteTime > fsinfos1[j + 1].LastWriteTime)
                    {

                        flag = true;
                        temp = fsinfos1[j];
                        fsinfos1[j] = fsinfos1[j + 1];
                        fsinfos1[j + 1] = temp;
                    }
                }
            }
            for (int i = 0; i < fsinfos1.Count-1; i++)
            {
                if (fsinfos1[i].Name.Substring(0, 14) == fsinfos1[i + 1].Name.Substring(0, 14))
                {
                    if (string.Compare(fsinfos1[i].Name,fsinfos1[i + 1].Name,false)>0)
                    {
                        fsinfos1.Remove(fsinfos1[i + 1]);
                    }
                    else
                    {
                        fsinfos1.Remove(fsinfos1[i]);
                    }
                    i--;
                }
            }
            if (checkBox5.Checked)
            {
                mulu = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)+"\\更新平台文件";
            }
            if (checkBox6.Checked)
            {
                mulu = comboBox6.Text;
                
            }
            if (mulu == "")
            {
                MessageBox.Show("请选择你需要提取到的路径。");
                return;
            }
            foreach (FileSystemInfo fsinfo in fsinfos1)
            {
                copyDirectory(dinfo + "\\" + fsinfo.Name, mulu);
                comboBox11.Items.Add(fsinfo.Name);
            }
            string cmd = "d:\\windows\\system32\\net.exe start digiwin.E10.DeploymentService";
            Execute(cmd, 0);
            cmd = "d:\\windows\\system32\\net.exe start digiwin.E10.APService";
            Execute(cmd, 0);
            cmd = "d:\\windows\\system32\\iisreset.exe /start";
            Execute(cmd, 0);
        }

        private void comboBox15_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox16.Items.Clear();
            if (comboBox15.Text != "")
            {
                dataGridView3.Rows[0].Cells[0].Value = comboBox15.Text;
                doc.Load("DataServer.xml");

                XmlNodeList nl;
                nl = doc.SelectNodes("/DataServer/Server");
                foreach (XmlNode nd in nl)
                {
                    if (nd.Attributes[0].Value == comboBox15.Text)
                    {
                        dataGridView3.Rows[0].Cells[2].Value = nd.Attributes[1].Value;
                        dataGridView3.Rows[0].Cells[3].Value = nd.Attributes[2].Value;
                        SaveConfig();
                    }
                }

                string str1 = "Data Source=" + comboBox15.Text + ";database=master;Uid=" + dataGridView3.Rows[0].Cells[2].Value + ";Pwd=" + dataGridView3.Rows[0].Cells[3].Value + ";";
                DataTable myTable = getTable(str1, "select name from sysdatabases", "sysdatabases");
                for (int i = 0; i < myTable.Rows.Count; i++)
                {
                    comboBox16.Items.Add(myTable.Rows[i]["name"].ToString());
                }
                
            }
        }

        private void comboBox16_SelectedIndexChanged(object sender, EventArgs e)
        {
            dataGridView3.Rows[0].Cells[1].Value = comboBox16.Text;
            SaveConfig();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            SendMail(dataGridView1, button8.Text);
        }

        private void button27_Click(object sender, EventArgs e)
        {
            SendMail(dataGridView1, button27.Text);
        }

        private void SendMail(DataGridView dtl1, string str)
        {
            Process[] ps = Process.GetProcesses();
            foreach (Process item in ps)
            {
                if (item.ProcessName == "OUTLOOK")
                {
                    item.Kill();
                    break;
                }
            }
            Outlook.Application olApp = new Outlook.Application();
            Outlook.MailItem mailItem = (Outlook.MailItem)olApp.CreateItem(Outlook.OlItemType.olMailItem);
            DataTable dt = new DataTable();
            int seq = 0;
            dt.Columns.Add("客户");
            dt.Columns.Add("填单人");
            dt.Columns.Add("BUG单号");
            dt.Columns.Add("程序名称");
            dt.Columns.Add("问题描述");
            dt.Columns.Add(str+"说明");
            dt.Rows.Add();
            dt.Rows[seq]["客户"] = dtl1.CurrentRow.Cells[4].Value;
            dt.Rows[seq]["填单人"] = dtl1.CurrentRow.Cells[2].Value;
            dt.Rows[seq]["BUG单号"] = dtl1.CurrentRow.Cells[3].Value;
            dt.Rows[seq]["程序名称"] = dtl1.CurrentRow.Cells[10].Value;
            dt.Rows[seq]["问题描述"] = dtl1.CurrentRow.Cells[14].Value;
            dt.Rows[seq][str+"说明"] = dtl1.CurrentRow.Cells[15].Value;
            StringBuilder sb = new StringBuilder();
            sb.Append("<HTML><HEAD>");
            sb.Append("<title>" + "" + "</title>");
            sb.Append("<META HTTP-EQUIV='content-type' CONTENT='text/html; charset=GB2312'> ");
            sb.Append("<script language=javascript>");
            sb.Append("self.resizeBy(0,0);");
            sb.Append("self.resizeTo(screen.availWidth,screen.availHeight);");
            sb.Append("</script>");
            sb.Append("<style type=text/css>");
            sb.Append("td{font-size: 9pt;border:solid 1 #000000;}");
            sb.Append("table{padding:3 0 3 0;border:solid 1 #000000;margin:0 0 0 0;BORDER-COLLAPSE: collapse;}");
            sb.Append("</style>");
            sb.Append("</HEAD>");
            sb.Append("<BODY  >");
            sb.Append("<BODY   onload = 'window.print()'>");
            sb.Append(dtl1.CurrentRow.Cells[11].Value.ToString() + ":<br>&nbsp;&nbsp;您好！<br>");
            sb.Append("<table cellSpacing='0' cellPadding='0' width ='100%' border='1'");
            sb.Append(">");
            sb.Append("<tr valign='middle' bgcolor=aqua>");
            foreach (DataColumn column in dt.Columns)
            {
                sb.Append("<td nowrap align='center'><b><span>" + column.ColumnName + "</span></b></td>");
            }
            sb.Append("</tr>");
            int iColsCount = dt.Columns.Count;
            int rowsCount = dt.Rows.Count - 1;
            for (int j = 0; j <= rowsCount; j++)
            {
                //sb.Append("<tr>");
                //sb.Append("<td>" + ((int)(j + 1)).ToString() + "</td>");
                for (int k = 0; k <= iColsCount - 1; k++)
                {
                    sb.Append("<td");
                    sb.Append(">");
                    object obj = dt.Rows[j][k];
                    if (obj == DBNull.Value)
                    {
                        // 如果是NULL则在HTML里面使用一个空格替换之  
                        obj = "&nbsp;";
                    }
                    if (obj.ToString() == "")
                    {
                        obj = "&nbsp;";
                    }
                    string strCellContent = obj.ToString().Trim();
                    sb.Append("<span>" + strCellContent + "</span>");
                    sb.Append("</td>");
                }
                sb.Append("</tr>");
            }
            sb.Append("</TABLE><br><br><br>");
            sb.Append("</BODY></HTML>");
            mailItem.To = dtl1.CurrentRow.Cells[12].Value.ToString();
            mailItem.CC = ("zhuxq@digiwin.biz");
            //mailItem.To = "pupei@digiwin.biz";

            mailItem.Subject = "Bug单"+str;
            mailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
            mailItem.HTMLBody = sb.ToString();
            ((Outlook._MailItem)mailItem).Send();
 
            mailItem = null;
            olApp = null;
            MessageBox.Show("邮件发送成功!");
        
        }

    }
}